alepha 0.9.3 → 0.9.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/form.d.ts CHANGED
@@ -1,41 +1,51 @@
1
1
  import * as _alepha_core0 from "alepha";
2
- import { Static, TObject, TSchema } from "alepha";
3
- import { InputHTMLAttributes } from "react";
2
+ import { Alepha, Static, TObject, TSchema } from "alepha";
3
+ import { InputHTMLAttributes, ReactNode } from "react";
4
+ import * as _alepha_logger0 from "alepha/logger";
4
5
 
5
- //#region src/hooks/useForm.d.ts
6
-
7
- /**
8
- * Custom hook to create a form with validation and field management.
9
- * This hook uses TypeBox schemas to define the structure and validation rules for the form.
10
- * It provides a way to handle form submission, field creation, and value management.
11
- *
12
- * @example
13
- * ```tsx
14
- * import { t } from "alepha";
15
- *
16
- * const form = useForm({
17
- * schema: t.object({
18
- * username: t.string(),
19
- * password: t.string(),
20
- * }),
21
- * handler: (values) => {
22
- * console.log("Form submitted with values:", values);
23
- * },
24
- * });
25
- *
26
- * return (
27
- * <form onSubmit={form.onSubmit}>
28
- * <input {...form.input("username")} />
29
- * <input {...form.input("password")} />
30
- * <button type="submit">Submit</button>
31
- * </form>
32
- * );
33
- * ```
34
- */
35
- declare const useForm: <T extends TObject>(options: UseFormOptions<T>) => UseFormReturn<T>;
36
- declare const getValueFromInput: (input: FormDataEntryValue, schema: TSchema) => any;
37
- declare const valueToInputEntry: (value: any) => string | number;
38
- type UseFormOptions<T extends TObject> = {
6
+ //#region src/services/FormModel.d.ts
7
+ declare class FormModel<T extends TObject> {
8
+ readonly id: string;
9
+ protected readonly options: FormCtrlOptions<T>;
10
+ protected readonly log: _alepha_logger0.Logger;
11
+ protected readonly alepha: Alepha;
12
+ protected readonly values: Record<string, any>;
13
+ input: SchemaToInput<T>;
14
+ constructor(id: string, options: FormCtrlOptions<T>);
15
+ readonly onSubmit: (event: FormEventLike) => Promise<void>;
16
+ protected parseValuesFromFormElement<T extends TObject>(options: FormCtrlOptions<T>, store: Record<string, any>): Record<string, any>;
17
+ protected getValueFromInputObject<T extends TObject>(options: FormCtrlOptions<T>, values: Record<string, any>, key: string, value: FormDataEntryValue): void;
18
+ protected createProxyFromSchema<T extends TObject>(options: FormCtrlOptions<T>, schema: TSchema, context: {
19
+ parent: string;
20
+ store: Record<string, any>;
21
+ }): SchemaToInput<T>;
22
+ protected createInputFromSchema<T extends TObject>(name: keyof Static<T> & string, options: FormCtrlOptions<T>, schema: TSchema, required: boolean, context: {
23
+ parent: string;
24
+ store: Record<string, any>;
25
+ }): InputField;
26
+ protected getValueFromInput(input: FormDataEntryValue, schema: TSchema): any;
27
+ protected valueToInputEntry(value: any): string | number | boolean;
28
+ }
29
+ type SchemaToInput<T extends TObject> = { [K in keyof T["properties"]]: T["properties"][K] extends TObject ? SchemaToInput<T["properties"][K]> : InputField };
30
+ interface FormEventLike {
31
+ currentTarget: any;
32
+ preventDefault: () => void;
33
+ stopPropagation: () => void;
34
+ }
35
+ interface InputField {
36
+ path: string;
37
+ required: boolean;
38
+ props: InputHTMLAttributesLike;
39
+ schema: TSchema;
40
+ set: (value: any) => void;
41
+ form: FormModel<any>;
42
+ }
43
+ type InputHTMLAttributesLike = Pick<InputHTMLAttributes<unknown>, "id" | "name" | "type" | "value" | "defaultValue" | "required" | "maxLength" | "minLength" | "aria-label"> & {
44
+ value?: any;
45
+ defaultValue?: any;
46
+ onChange?: (event: any) => void;
47
+ };
48
+ type FormCtrlOptions<T extends TObject> = {
39
49
  /**
40
50
  * The schema defining the structure and validation rules for the form.
41
51
  * This should be a TypeBox schema object.
@@ -71,42 +81,82 @@ type UseFormOptions<T extends TObject> = {
71
81
  }) => void;
72
82
  onChange?: (key: string, value: any, store: Record<string, any>) => void;
73
83
  };
74
- type UseFormReturn<T extends TObject> = {
75
- /**
76
- * Function to handle form submission.
77
- * This should be attached to the form's onSubmit event.
78
- *
79
- * @example
80
- * ```tsx
81
- * const form = useForm();
82
- *
83
- * return <form onSubmit={form.onSubmit}></form>;
84
- * ```
85
- */
86
- onSubmit?: (event: FormEventLike) => void;
87
- /**
88
- * Creates an input field for the specified schema property.
89
- */
90
- input: SchemaToInput<T>;
91
- };
92
- type SchemaToInput<T extends TObject> = { [K in keyof T["properties"]]: T["properties"][K] extends TObject ? SchemaToInput<T["properties"][K]> : InputField };
93
- interface FormEventLike {
94
- currentTarget: HTMLFormElement;
95
- preventDefault: () => void;
84
+ //#endregion
85
+ //#region src/components/FormState.d.ts
86
+ declare const FormState: <T extends TObject>(props: {
87
+ form: FormModel<T>;
88
+ children: (state: {
89
+ loading: boolean;
90
+ dirty: boolean;
91
+ }) => ReactNode;
92
+ }) => ReactNode;
93
+ //#endregion
94
+ //#region src/hooks/useForm.d.ts
95
+ /**
96
+ * Custom hook to create a form with validation and field management.
97
+ * This hook uses TypeBox schemas to define the structure and validation rules for the form.
98
+ * It provides a way to handle form submission, field creation, and value management.
99
+ *
100
+ * @example
101
+ * ```tsx
102
+ * import { t } from "alepha";
103
+ *
104
+ * const form = useForm({
105
+ * schema: t.object({
106
+ * username: t.string(),
107
+ * password: t.string(),
108
+ * }),
109
+ * handler: (values) => {
110
+ * console.log("Form submitted with values:", values);
111
+ * },
112
+ * });
113
+ *
114
+ * return (
115
+ * <form onSubmit={form.onSubmit}>
116
+ * <input {...form.input("username")} />
117
+ * <input {...form.input("password")} />
118
+ * <button type="submit">Submit</button>
119
+ * </form>
120
+ * );
121
+ * ```
122
+ */
123
+ declare const useForm: <T extends TObject>(options: FormCtrlOptions<T>) => FormModel<T>;
124
+ //#endregion
125
+ //#region src/hooks/useFormState.d.ts
126
+ interface UseFormStateReturn<T extends TObject> {
127
+ loading: boolean;
128
+ dirty: boolean;
129
+ values?: T;
130
+ error?: Error;
96
131
  }
97
- interface InputField {
132
+ type FormStateEvent = "change" | "submit" | "error";
133
+ declare const useFormState: <T extends TObject>(target: FormModel<T> | {
134
+ form: FormModel<T>;
98
135
  path: string;
99
- props: InputHTMLAttributesLike;
100
- schema: TSchema;
101
- set: (value: any) => void;
102
- }
103
- type InputHTMLAttributesLike = Pick<InputHTMLAttributes<unknown>, "id" | "name" | "type" | "value" | "defaultValue" | "onChange" | "required" | "maxLength" | "minLength" | "aria-label"> & {
104
- value?: any;
105
- defaultValue?: any;
106
- };
107
- //# sourceMappingURL=useForm.d.ts.map
136
+ }, events?: FormStateEvent[]) => UseFormStateReturn<T>;
108
137
  //#endregion
109
138
  //#region src/index.d.ts
139
+ declare module "alepha" {
140
+ interface Hooks {
141
+ "form:change": {
142
+ id: string;
143
+ path: string;
144
+ };
145
+ "form:submit:begin": {
146
+ id: string;
147
+ };
148
+ "form:submit:success": {
149
+ id: string;
150
+ };
151
+ "form:submit:error": {
152
+ id: string;
153
+ error: Error;
154
+ };
155
+ "form:submit:end": {
156
+ id: string;
157
+ };
158
+ }
159
+ }
110
160
  /**
111
161
  * React hooks for managing forms in Alepha applications.
112
162
  *
@@ -119,8 +169,6 @@ type InputHTMLAttributesLike = Pick<InputHTMLAttributes<unknown>, "id" | "name"
119
169
  * @module alepha.react.form
120
170
  */
121
171
  declare const AlephaReactForm: _alepha_core0.Service<_alepha_core0.Module>;
122
- //# sourceMappingURL=index.d.ts.map
123
-
124
172
  //#endregion
125
- export { AlephaReactForm, FormEventLike, InputField, InputHTMLAttributesLike, SchemaToInput, UseFormOptions, UseFormReturn, getValueFromInput, useForm, valueToInputEntry };
173
+ export { AlephaReactForm, FormCtrlOptions, FormEventLike, FormModel, FormState, FormStateEvent, InputField, InputHTMLAttributesLike, SchemaToInput, UseFormStateReturn, useForm, useFormState };
126
174
  //# sourceMappingURL=index.d.ts.map
package/react/head.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core0 from "alepha";
3
2
  import { Descriptor, KIND } from "alepha";
4
- import { PageConfigSchema, PageReactContext, PageRoute, RouterState, TPropsDefault, TPropsParentDefault } from "alepha/react";
3
+ import { PageConfigSchema, PageRoute, ReactRouterState, TPropsDefault, TPropsParentDefault } from "alepha/react";
4
+ import { ServerTimingProvider } from "alepha/server";
5
5
 
6
6
  //#region src/interfaces/Head.d.ts
7
7
  interface Head extends SimpleHead {
@@ -43,16 +43,14 @@ interface SimpleHead {
43
43
  content: string;
44
44
  }>;
45
45
  }
46
- //# sourceMappingURL=Head.d.ts.map
47
46
  //#endregion
48
47
  //#region src/providers/HeadProvider.d.ts
49
48
  declare class HeadProvider {
50
49
  global?: Head | (() => Head);
51
50
  protected getGlobalHead(): Head | undefined;
52
- fillHead(state: RouterState, context: PageReactContext): void;
53
- protected fillHeadByPage(page: PageRoute, context: PageReactContext, props: Record<string, any>): void;
51
+ fillHead(state: ReactRouterState): void;
52
+ protected fillHeadByPage(page: PageRoute, state: ReactRouterState, props: Record<string, any>): void;
54
53
  }
55
- //# sourceMappingURL=HeadProvider.d.ts.map
56
54
  //#endregion
57
55
  //#region src/descriptors/$head.d.ts
58
56
  /**
@@ -67,8 +65,6 @@ declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
67
65
  protected readonly provider: HeadProvider;
68
66
  protected onInit(): void;
69
67
  }
70
- //# sourceMappingURL=$head.d.ts.map
71
-
72
68
  //#endregion
73
69
  //#region src/hooks/useHead.d.ts
74
70
  /**
@@ -88,28 +84,27 @@ declare class HeadDescriptor extends Descriptor<HeadDescriptorOptions> {
88
84
  * }
89
85
  * ```
90
86
  */
91
- declare const useHead: (options?: UseHeadOptions) => void;
87
+ declare const useHead: (options?: UseHeadOptions) => UseHeadReturn;
92
88
  type UseHeadOptions = Head | ((previous?: Head) => Head);
93
89
  type UseHeadReturn = [Head, (head?: Head | ((previous?: Head) => Head)) => void];
94
- //# sourceMappingURL=useHead.d.ts.map
95
90
  //#endregion
96
91
  //#region src/providers/ServerHeadProvider.d.ts
97
92
  declare class ServerHeadProvider {
98
93
  protected readonly headProvider: HeadProvider;
94
+ protected readonly serverTimingProvider: ServerTimingProvider;
99
95
  protected readonly onServerRenderEnd: _alepha_core1.HookDescriptor<"react:server:render:end">;
100
96
  renderHead(template: string, head: SimpleHead): string;
101
97
  protected mergeAttributes(existing: string, attrs: Record<string, string>): string;
102
98
  protected parseAttributes(attrStr: string): Record<string, string>;
103
99
  protected escapeHtml(str: string): string;
104
100
  }
105
- //# sourceMappingURL=ServerHeadProvider.d.ts.map
106
101
  //#endregion
107
102
  //#region src/index.d.ts
108
103
  declare module "alepha/react" {
109
104
  interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
110
105
  head?: Head | ((props: TProps, previous?: Head) => Head);
111
106
  }
112
- interface PageReactContext {
107
+ interface ReactRouterState {
113
108
  head: Head;
114
109
  }
115
110
  }
@@ -119,9 +114,7 @@ declare module "alepha/react" {
119
114
  * @see {@link ServerHeadProvider}
120
115
  * @module alepha.react.head
121
116
  */
122
- declare const AlephaReactHead: _alepha_core0.Service<_alepha_core0.Module>;
123
- //# sourceMappingURL=index.d.ts.map
124
-
117
+ declare const AlephaReactHead: _alepha_core1.Service<_alepha_core1.Module>;
125
118
  //#endregion
126
119
  export { $head, AlephaReactHead, Head, HeadDescriptor, HeadDescriptorOptions, ServerHeadProvider, SimpleHead, UseHeadOptions, UseHeadReturn, useHead };
127
120
  //# sourceMappingURL=index.d.ts.map
package/react/i18n.d.ts CHANGED
@@ -1,15 +1,22 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core0 from "alepha";
3
2
  import { Alepha, Descriptor, KIND } from "alepha";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
4
  import * as _alepha_server_cookies0 from "alepha/server/cookies";
5
5
  import * as _sinclair_typebox0 from "@sinclair/typebox";
6
6
 
7
+ //#region src/hooks/useI18n.d.ts
8
+ /**
9
+ * Hook to access the i18n service.
10
+ */
11
+ declare const useI18n: <S extends object, K extends keyof ServiceDictionary<S>>() => I18nProvider<object, never>;
12
+ type ServiceDictionary<T extends object> = { [K in keyof T]: T[K] extends DictionaryDescriptor<infer U> ? U : never };
13
+ //#endregion
7
14
  //#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<{
15
+ declare class I18nProvider<S extends object, K extends keyof ServiceDictionary<S>> {
16
+ protected logger: _alepha_logger0.Logger;
17
+ protected alepha: Alepha;
18
+ protected cookie: _alepha_server_cookies0.AbstractCookieDescriptor<_sinclair_typebox0.TString>;
19
+ readonly registry: Array<{
13
20
  name: string;
14
21
  lang: string;
15
22
  loader: () => Promise<Record<string, string>>;
@@ -18,16 +25,23 @@ declare class I18nProvider {
18
25
  options: {
19
26
  fallbackLang: string;
20
27
  };
28
+ numberFormat: {
29
+ format: (value: number) => string;
30
+ };
21
31
  get languages(): string[];
22
- onRender: _alepha_core1.HookDescriptor<"server:onRequest">;
23
- onStart: _alepha_core1.HookDescriptor<"start">;
32
+ protected readonly onRender: _alepha_core1.HookDescriptor<"server:onRequest">;
33
+ protected readonly onStart: _alepha_core1.HookDescriptor<"start">;
34
+ protected createFormatters(): void;
24
35
  setLang(lang: string): Promise<void>;
36
+ protected readonly mutate: _alepha_core1.HookDescriptor<"state:mutate">;
25
37
  get lang(): string;
26
38
  translate: (key: string, args?: string[]) => string;
39
+ readonly tr: (key: keyof ServiceDictionary<S>[K] | string, options?: {
40
+ args?: string[];
41
+ default?: string;
42
+ }) => string;
27
43
  protected render(item: string, args: string[]): string;
28
44
  }
29
- //# sourceMappingURL=I18nProvider.d.ts.map
30
-
31
45
  //#endregion
32
46
  //#region src/descriptors/$dictionary.d.ts
33
47
  /**
@@ -38,7 +52,7 @@ declare class I18nProvider {
38
52
  *
39
53
  * @example
40
54
  * ```ts
41
- * import { $dictionary } from "alepha/react/i18n";
55
+ * import { $dictionary } from "alepha/react-i18n";
42
56
  *
43
57
  * const Example = () => {
44
58
  * const { tr } = useI18n<App, "en">();
@@ -73,23 +87,9 @@ interface DictionaryDescriptorOptions<T extends Record<string, string>> {
73
87
  }>;
74
88
  }
75
89
  declare class DictionaryDescriptor<T extends Record<string, string>> extends Descriptor<DictionaryDescriptorOptions<T>> {
76
- protected provider: I18nProvider;
90
+ protected provider: I18nProvider<object, never>;
77
91
  protected onInit(): void;
78
92
  }
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
93
  //#endregion
94
94
  //#region src/index.d.ts
95
95
  declare module "alepha" {
@@ -104,9 +104,7 @@ declare module "alepha" {
104
104
  *
105
105
  * @module alepha.react.i18n
106
106
  */
107
- declare const AlephaReactI18n: _alepha_core0.Service<_alepha_core0.Module>;
108
- //# sourceMappingURL=index.d.ts.map
109
-
107
+ declare const AlephaReactI18n: _alepha_core1.Service<_alepha_core1.Module>;
110
108
  //#endregion
111
109
  export { $dictionary, AlephaReactI18n, DictionaryDescriptor, DictionaryDescriptorOptions, I18nProvider, ServiceDictionary, useI18n };
112
110
  //# sourceMappingURL=index.d.ts.map