@gaddario98/react-core 2.0.2 → 2.0.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.
@@ -0,0 +1,236 @@
1
+ import * as _gaddario98_react_state from '@gaddario98/react-state';
2
+ import * as React$1 from 'react';
3
+ import React__default, { PropsWithChildren, JSX } from 'react';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import * as _tanstack_react_form from '@tanstack/react-form';
6
+ import { FormOptions, DeepKeys, DeepValue, FieldApi, FieldState, ReactFormExtendedApi } from '@tanstack/react-form';
7
+ import * as jotai from 'jotai';
8
+
9
+ interface FormNotificationMessage {
10
+ message: string;
11
+ type: 'success' | 'error' | 'info' | 'warning';
12
+ autoHideDuration?: number;
13
+ textTransOption?: Record<string, unknown>;
14
+ ns?: string;
15
+ }
16
+ interface FormTranslationOptions {
17
+ [key: string]: string | number | boolean | undefined;
18
+ ns?: string;
19
+ }
20
+ interface FormConfigProps {
21
+ formFieldContainer: React.FC<PropsWithChildren>;
22
+ showNotification?: (notification: FormNotificationMessage) => void;
23
+ translateText?: (key: string, options?: FormTranslationOptions) => string;
24
+ }
25
+ declare const formConfigAtom: _gaddario98_react_state.PrimitiveAtom<FormConfigProps>;
26
+ declare const useFormConfigValue: () => FormConfigProps;
27
+ declare const useFormConfigState: () => [FormConfigProps, (value: FormConfigProps) => void];
28
+ declare const useFormConfigReset: () => () => void;
29
+
30
+ interface UseCustomFormOptions<TData extends FieldValues> extends FormOptions<TData, any, any, any, any, any, any, any, any, any, any, any> {
31
+ formId?: string;
32
+ }
33
+ declare function useJotaiForm<TData extends FieldValues>(formOptions: UseCustomFormOptions<TData>): _tanstack_react_form.ReactFormExtendedApi<TData, any, any, any, any, any, any, any, any, any, any, any>;
34
+
35
+ interface FormElements {
36
+ index: number;
37
+ element: JSX.Element;
38
+ renderInFooter: boolean;
39
+ renderInHeader: boolean;
40
+ isSubmit?: boolean;
41
+ }
42
+ declare const useFormManager: <F extends FieldValues = FieldValues>({ data, onInvalid, submit, notification, formOptions, onValuesChange, globalErrorNs, id, }: UseFormManagerProps<F>) => {
43
+ elements: FormElements[];
44
+ formContents: (FormManagerConfig<F> | ((props: FormFunctionProps<F>) => FormManagerConfig<F>) | Submit<F, SubmitKeysArg<F>>)[];
45
+ errors: any[];
46
+ formValues: F;
47
+ setValue: SetValueFunction<F>;
48
+ };
49
+
50
+ interface UseFormValuesProps {
51
+ formId: string;
52
+ scopeId?: string;
53
+ }
54
+ declare const useFormValues: <F extends FieldValues>({ formId, }: UseFormValuesProps) => FormFunctionProps<F>;
55
+
56
+ type FieldValues = Record<string, any>;
57
+ type SetValueFunction<F extends FieldValues> = <TField extends DeepKeys<F>>(field: TField, value: DeepValue<F, TField>) => void;
58
+ type GetFormValuesFunction<F extends FieldValues> = {
59
+ <TField extends DeepKeys<F>>(key: TField): DeepValue<F, TField> | undefined;
60
+ <TField extends DeepKeys<F>>(key: TField, defaultValue: DeepValue<F, TField>): NonNullable<DeepValue<F, TField>>;
61
+ };
62
+ type GenericFormApi<TData extends FieldValues> = ReactFormExtendedApi<TData, any, any, any, any, any, any, any, any, any, any, any>;
63
+ type GenericFieldApi<TData extends FieldValues> = FieldApi<TData, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
64
+ type GenericFieldState<TData extends FieldValues> = FieldState<TData, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
65
+ type SubmitKeysArg<T> = ReadonlyArray<keyof T> | undefined;
66
+ type SubmitPayload<T, K extends SubmitKeysArg<T>> = K extends ReadonlyArray<keyof T> ? Pick<T, K[number]> : T;
67
+ type FormFunctionProps<F extends FieldValues> = {
68
+ get: GetFormValuesFunction<F>;
69
+ set: SetValueFunction<F>;
70
+ };
71
+ interface Submit<T extends FieldValues = FieldValues, K extends SubmitKeysArg<T> = SubmitKeysArg<T>> {
72
+ onSuccess?: (values: T) => void;
73
+ onError?: (err: Error) => void;
74
+ values?: K;
75
+ index?: number;
76
+ buttonProps?: Record<string, unknown>;
77
+ renderInFooter?: boolean;
78
+ hidden?: boolean;
79
+ renderInHeader?: boolean;
80
+ isDisabled?: boolean;
81
+ isDraggable?: boolean;
82
+ isInDraggableView?: boolean;
83
+ isLoading?: boolean;
84
+ usedBoxes?: number;
85
+ type?: 'submit' | 'button';
86
+ key?: string;
87
+ component?: (props: {
88
+ onClick: () => void;
89
+ index: number;
90
+ key: string;
91
+ type: 'submit' | 'button';
92
+ }) => React__default.JSX.Element;
93
+ }
94
+ interface ViewSettingsContainerProps {
95
+ children: React__default.ReactNode;
96
+ }
97
+ type FormManagerProps<T extends FieldValues = FieldValues> = {
98
+ data: Array<FormManagerConfig<T> | ((props: FormFunctionProps<T>) => FormManagerConfig<T>)>;
99
+ defaultValues: T;
100
+ onInvalid?: (err: unknown) => void;
101
+ isHiddenErrors?: boolean;
102
+ ns?: string;
103
+ globalErrorNs?: string;
104
+ submit?: Array<Submit<T>>;
105
+ notification?: {
106
+ success?: FormNotificationMessage | ((res: unknown) => FormNotificationMessage);
107
+ error?: FormNotificationMessage | ((error: string) => FormNotificationMessage);
108
+ ns?: string;
109
+ };
110
+ onValuesChange?: (props: T, setValue: (name: any, value: any) => void) => void;
111
+ formSettings?: UseCustomFormOptions<T>;
112
+ isDraggable?: boolean;
113
+ isInDraggableView?: boolean;
114
+ id?: string;
115
+ viewSettings?: {
116
+ container?: React__default.ComponentType<ViewSettingsContainerProps>;
117
+ submitContainer?: React__default.ComponentType<ViewSettingsContainerProps>;
118
+ bodyContainer?: React__default.ComponentType<ViewSettingsContainerProps>;
119
+ containerProps?: Record<string, unknown>;
120
+ submitContainerProps?: Record<string, unknown>;
121
+ bodyContainerProps?: Record<string, unknown>;
122
+ };
123
+ };
124
+ type UseFormManagerProps<T extends FieldValues> = {
125
+ data: Array<FormManagerConfig<T> | ((props: FormFunctionProps<T>) => FormManagerConfig<T>)>;
126
+ onInvalid?: (err: unknown) => void;
127
+ formOptions: UseCustomFormOptions<T>;
128
+ isHiddenErrors?: boolean;
129
+ ns?: string;
130
+ globalErrorNs?: string;
131
+ submit?: Array<Submit<T>>;
132
+ notification?: {
133
+ success?: FormNotificationMessage | ((res: unknown) => FormNotificationMessage);
134
+ error?: FormNotificationMessage | ((error: string) => FormNotificationMessage);
135
+ ns?: string;
136
+ };
137
+ onValuesChange?: (props: T, setValue: (name: any, value: any) => void) => void;
138
+ id?: string;
139
+ };
140
+ interface FieldComponentProps<T extends FieldValues> {
141
+ value: any;
142
+ onChange: (value: any) => void;
143
+ onBlur: () => void;
144
+ error?: boolean;
145
+ errorMessage?: string;
146
+ formValues?: T;
147
+ label?: string;
148
+ helperMessage?: string;
149
+ }
150
+ type FormManagerConfig<T extends FieldValues> = Omit<FormFieldConfig<T>, 'field' | 'fieldState' | 'fieldValues'>;
151
+ type MappedFormItemsFunction<F extends FieldValues, ComponentType> = (props: FormFunctionProps<F>) => ComponentType;
152
+ type Rules = {
153
+ validate?: (value: any) => string | undefined | Promise<string | undefined>;
154
+ onChange?: (value: any) => void;
155
+ onBlur?: () => void;
156
+ onMount?: (value: any) => void;
157
+ };
158
+ type FormFieldConfig<T extends FieldValues> = {
159
+ name: any;
160
+ label?: string;
161
+ rules?: Rules | MappedFormItemsFunction<T, Rules>;
162
+ field: GenericFieldApi<T>;
163
+ fieldState: GenericFieldState<T>;
164
+ containerStyle?: string;
165
+ component: (props: Omit<FieldComponentProps<T>, 'formValues'>) => React__default.JSX.Element;
166
+ container?: React__default.FC<PropsWithChildren>;
167
+ ns?: string;
168
+ errorNs?: string;
169
+ index?: number;
170
+ renderInFooter?: boolean;
171
+ renderInHeader?: boolean;
172
+ usedBoxes?: number;
173
+ key?: string;
174
+ isDraggable?: boolean;
175
+ isInDraggableView?: boolean;
176
+ helper?: {
177
+ text?: string;
178
+ translationOption?: FormTranslationOptions;
179
+ };
180
+ onFieldChange?: (value: any) => void;
181
+ hidden?: boolean | MappedFormItemsFunction<T, boolean>;
182
+ };
183
+ interface ErrorComponentProps {
184
+ message?: string;
185
+ fieldName?: string;
186
+ }
187
+ interface FormContainerProps {
188
+ className?: string;
189
+ children: React__default.ReactNode;
190
+ }
191
+ interface FormFieldProps<T extends FieldValues> {
192
+ config: FormFieldConfig<T>;
193
+ onFieldChange?: (value: T) => void;
194
+ ns?: string;
195
+ globalErrorNs?: string;
196
+ container?: React__default.FC<PropsWithChildren>;
197
+ }
198
+
199
+ interface DefaultFormContainerProps {
200
+ children: React.ReactNode;
201
+ }
202
+ declare let DefaultContainer: ({ children }: ViewSettingsContainerProps) => React$1.ReactNode;
203
+ declare const setDefaultFormContainer: (val: ({ children, }: ViewSettingsContainerProps) => React.ReactNode) => void;
204
+ declare const DefaultFormContainer: <_T extends FieldValues = FieldValues>({ children, }: ViewSettingsContainerProps) => react_jsx_runtime.JSX.Element;
205
+
206
+ declare const FormManager: <T extends Record<string, any> = FieldValues>({ data, defaultValues, onInvalid, submit, ns, globalErrorNs, notification, formSettings, viewSettings, onValuesChange, id, }: FormManagerProps<T>) => react_jsx_runtime.JSX.Element;
207
+
208
+ declare const FormField: <T extends FieldValues>({ config, onFieldChange, ns: globalNs, globalErrorNs, }: FormFieldProps<T>) => react_jsx_runtime.JSX.Element;
209
+
210
+ interface FormStoreEntry<F extends FieldValues = FieldValues> {
211
+ formValues: F;
212
+ setValue: SetValueFunction<F>;
213
+ }
214
+ declare const DEFAULT_FORM_ENTRY: FormStoreEntry<FieldValues>;
215
+ /**
216
+ * Global atom storing all form state.
217
+ * Key format: "scopeId:formId" or just "formId" for backward compatibility.
218
+ */
219
+ declare const formAtom: jotai.PrimitiveAtom<Record<string, FormStoreEntry<FieldValues>>> & {
220
+ init: Record<string, FormStoreEntry<FieldValues>>;
221
+ };
222
+ /**
223
+ * Helper to generate composite keys for forms.
224
+ */
225
+ declare const getFormCompositeKey: (scopeId: string, key: string) => string;
226
+ /**
227
+ * Creates a derived atom for accessing forms of a specific scope.
228
+ */
229
+ declare const createScopeFormsAtom: (scopeId: string) => jotai.WritableAtom<Record<string, FormStoreEntry<FieldValues>>, [update: Record<string, FormStoreEntry<FieldValues>>], void>;
230
+ declare const createFormSelector: <F extends FieldValues = FieldValues>(formId: string) => jotai.Atom<FormStoreEntry<F>>;
231
+ declare const useFormValue: <F extends FieldValues>(formId: string) => FormStoreEntry<F>;
232
+ declare const useFormState: <F extends FieldValues>() => [Record<string, FormStoreEntry<F>>, (value: Record<string, FormStoreEntry<F>>) => void];
233
+ declare const useSetFormState: <F extends FieldValues>(formId: string) => (val: Partial<FormStoreEntry<F>>) => void;
234
+
235
+ export { DEFAULT_FORM_ENTRY, DefaultContainer, DefaultFormContainer, FormField, FormManager, createFormSelector, createScopeFormsAtom, formAtom, formConfigAtom, getFormCompositeKey, setDefaultFormContainer, useFormConfigReset, useFormConfigState, useFormConfigValue, useFormManager, useFormState, useFormValue, useFormValues, useJotaiForm, useSetFormState };
236
+ export type { DefaultFormContainerProps, ErrorComponentProps, FieldComponentProps, FieldValues, FormConfigProps, FormContainerProps, FormElements, FormFieldConfig, FormFieldProps, FormFunctionProps, FormManagerConfig, FormManagerProps, FormNotificationMessage, FormStoreEntry, FormTranslationOptions, GenericFieldApi, GenericFieldState, GenericFormApi, GetFormValuesFunction, MappedFormItemsFunction, Rules, SetValueFunction, Submit, SubmitKeysArg, SubmitPayload, UseCustomFormOptions, UseFormManagerProps, UseFormValuesProps, ViewSettingsContainerProps };
@@ -0,0 +1,155 @@
1
+ import * as _gaddario98_react_state from '@gaddario98/react-state';
2
+
3
+ type Locale = string;
4
+ type TranslationResources = Record<string, any>;
5
+ /**
6
+ * Opzioni di formattazione per i diversi tipi di valori
7
+ */
8
+ interface FormatOptions {
9
+ number?: Intl.NumberFormatOptions;
10
+ date?: Intl.DateTimeFormatOptions;
11
+ currency?: Intl.NumberFormatOptions & {
12
+ currency?: string;
13
+ };
14
+ }
15
+ /**
16
+ * Opzioni per la traduzione con supporto parametri avanzati
17
+ */
18
+ interface TranslationOptions {
19
+ [key: string]: any;
20
+ defaultValue?: string;
21
+ /**
22
+ * Opzioni di formattazione per i parametri specifici
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * t('welcome', {
27
+ * price: 1234.56,
28
+ * formatOptions: {
29
+ * price: {
30
+ * currency: { currency: 'EUR', minimumFractionDigits: 2 }
31
+ * }
32
+ * }
33
+ * })
34
+ * ```
35
+ */
36
+ formatOptions?: Record<string, FormatOptions>;
37
+ ns?: string;
38
+ }
39
+ /**
40
+ * Funzione di traduzione con supporto parametri avanzati
41
+ *
42
+ * @example Interpolazione semplice
43
+ * ```ts
44
+ * t('welcome', { name: 'Mario' })
45
+ * // "Benvenuto {{name}}" -> "Benvenuto Mario"
46
+ * ```
47
+ *
48
+ * @example Formattazione numeri
49
+ * ```ts
50
+ * t('items_count', { count: 1000 })
51
+ * // "Hai {{count, number}} elementi" -> "Hai 1,000 elementi"
52
+ * ```
53
+ *
54
+ * @example Formattazione date
55
+ * ```ts
56
+ * t('last_login', { date: new Date() })
57
+ * // "Ultimo accesso: {{date, date}}" -> "Ultimo accesso: 15/12/2025"
58
+ * ```
59
+ *
60
+ * @example Formattazione valuta
61
+ * ```ts
62
+ * t('total', {
63
+ * price: 99.99,
64
+ * formatOptions: {
65
+ * price: { currency: { currency: 'EUR' } }
66
+ * }
67
+ * })
68
+ * // "Totale: {{price, currency}}" -> "Totale: €99.99"
69
+ * ```
70
+ *
71
+ * @example Pluralizzazione
72
+ * ```ts
73
+ * t('items', { count: 0 })
74
+ * // "{{count, plural, =0{Nessun elemento} one{Un elemento} other{# elementi}}}"
75
+ * // -> "Nessun elemento"
76
+ *
77
+ * t('items', { count: 1 })
78
+ * // -> "Un elemento"
79
+ *
80
+ * t('items', { count: 5 })
81
+ * // -> "5 elementi"
82
+ * ```
83
+ *
84
+ * @example Selezione
85
+ * ```ts
86
+ * t('greeting', { gender: 'male' })
87
+ * // "{{gender, select, male{Benvenuto} female{Benvenuta} other{Benvenuto/a}}}"
88
+ * // -> "Benvenuto"
89
+ * ```
90
+ */
91
+ type TranslateFunction = (key: string, options?: TranslationOptions) => string;
92
+ interface I18nConfig {
93
+ defaultLocale: Locale;
94
+ supportedLocales: Array<Locale>;
95
+ }
96
+
97
+ interface LocalizationConfigProps {
98
+ currentLocale: Locale;
99
+ locales: Record<Locale, TranslationResources>;
100
+ }
101
+ declare const localizationConfigAtom: _gaddario98_react_state.PrimitiveAtom<LocalizationConfigProps>;
102
+ declare const useLocalizationConfigValue: () => LocalizationConfigProps;
103
+ declare const useLocalizationConfigState: () => [LocalizationConfigProps, (value: LocalizationConfigProps) => void];
104
+ declare const useLocalizationConfigReset: () => () => void;
105
+ /**
106
+ * Hook per gestire le operazioni di localization
107
+ */
108
+ declare const useLocalizationActions: () => {
109
+ /**
110
+ * Aggiunge o aggiorna una locale con le sue risorse
111
+ */
112
+ addLocale: (locale: Locale, resources: TranslationResources) => void;
113
+ /**
114
+ * Switch alla locale specificata
115
+ */
116
+ switchLocale: (locale: Locale) => void;
117
+ /**
118
+ * Inizializza con una locale di default
119
+ */
120
+ initializeLocale: (locale: Locale, resources: TranslationResources) => void;
121
+ };
122
+
123
+ /**
124
+ * Funzione core per risolvere una traduzione.
125
+ */
126
+ declare const resolveTranslation: (key: string, resources: TranslationResources, options?: TranslationOptions, locale?: string) => string;
127
+
128
+ declare const useTranslation: (_ns?: string) => {
129
+ t: TranslateFunction;
130
+ locale: Locale;
131
+ };
132
+
133
+ /**
134
+ * Crea un'istanza di traduzione per l'uso lato server (o fuori dai componenti React).
135
+ */
136
+ declare const createServerTranslator: (resources: TranslationResources, locale?: Locale) => {
137
+ t: TranslateFunction;
138
+ locale: Locale;
139
+ };
140
+
141
+ type TranslationFunction = (key: string, options?: TranslationOptions) => string;
142
+ /**
143
+ * Hook per tradurre testi che si adatta al sistema di traduzione interno.
144
+ * Wrapper di retro-compatibilità per useTranslation.
145
+ *
146
+ * @param ns - Namespace opzionale (ignorato nella nuova implementazione)
147
+ * @returns Un oggetto con la funzione traslateText (e alias t)
148
+ */
149
+ declare const useTranslatedText: (ns?: string) => {
150
+ traslateText: (text: string, options?: TranslationOptions) => string;
151
+ t: (text: string, options?: TranslationOptions) => string;
152
+ };
153
+
154
+ export { createServerTranslator, localizationConfigAtom, resolveTranslation, useLocalizationActions, useLocalizationConfigReset, useLocalizationConfigState, useLocalizationConfigValue, useTranslatedText, useTranslation };
155
+ export type { FormatOptions, I18nConfig, Locale, LocalizationConfigProps, TranslateFunction, TranslationFunction, TranslationOptions, TranslationResources };
@@ -0,0 +1,37 @@
1
+ import * as _gaddario98_react_state from '@gaddario98/react-state';
2
+
3
+ interface NotificationMessage {
4
+ id: string;
5
+ message: string;
6
+ type: 'success' | 'error' | 'info' | 'warning';
7
+ autoHideDuration?: number;
8
+ textTransOption?: Record<string, unknown>;
9
+ ns?: string;
10
+ }
11
+ type TypeNotification = 'like' | 'message' | 'comments' | 'follow';
12
+ interface UserNotification {
13
+ uid: string;
14
+ type: TypeNotification;
15
+ postId?: string;
16
+ typePost?: string;
17
+ token: string;
18
+ message?: string;
19
+ data?: Date;
20
+ read: boolean;
21
+ notificationId: string;
22
+ nickname?: string;
23
+ titlePost?: string;
24
+ }
25
+ type NotificationConfig = Partial<Omit<NotificationMessage, 'id'>>;
26
+
27
+ declare const useNotification: (ns?: string) => {
28
+ showNotification: (notification: Omit<NotificationMessage, "id">) => void;
29
+ clearNotification: () => void;
30
+ };
31
+
32
+ declare const notificationAtom: _gaddario98_react_state.PrimitiveAtom<NotificationMessage | null>;
33
+ declare const useNotificationValue: () => NotificationMessage | null;
34
+ declare const useNotificationState: () => [NotificationMessage | null, (value: NotificationMessage | null) => void];
35
+
36
+ export { notificationAtom, useNotification, useNotificationState, useNotificationValue };
37
+ export type { NotificationConfig, NotificationMessage, UserNotification };