zustic 1.1.0 → 1.1.2
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/dist/hook-form/index.d.mts +291 -0
- package/dist/hook-form/index.d.ts +291 -0
- package/dist/hook-form/index.js +1 -0
- package/dist/hook-form/index.mjs +1 -0
- package/dist/i18n/index.d.mts +8 -23
- package/dist/i18n/index.d.ts +8 -23
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/index.mjs +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Required field validation rule.
|
|
5
|
+
* Can be a simple boolean or an object with custom error message.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Simple required
|
|
9
|
+
* required: true
|
|
10
|
+
*
|
|
11
|
+
* // With custom message
|
|
12
|
+
* required: { value: true, message: "Email is required" }
|
|
13
|
+
*/
|
|
14
|
+
type RequiredRule = boolean | {
|
|
15
|
+
value: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Numeric validation rule for min/max constraints.
|
|
20
|
+
* Can be a plain number or an object with custom error message.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Simple min value
|
|
24
|
+
* min: 18
|
|
25
|
+
*
|
|
26
|
+
* // With custom message
|
|
27
|
+
* min: { value: 18, message: "Must be 18 or older" }
|
|
28
|
+
*/
|
|
29
|
+
type NumberRule = number | {
|
|
30
|
+
value: number;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Individual form field state and configuration.
|
|
35
|
+
* Tracks value, error, validation rules, and user interaction state.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the field value
|
|
38
|
+
*
|
|
39
|
+
* @property value - Current field value
|
|
40
|
+
* @property error - Current error message (if any)
|
|
41
|
+
* @property touched - Whether field has been focused/interacted with
|
|
42
|
+
* @property isDirty - Whether field has been modified from initial value
|
|
43
|
+
* @property required - Required validation rule
|
|
44
|
+
* @property pattern - Regex pattern for string validation
|
|
45
|
+
* @property min - Minimum value or length
|
|
46
|
+
* @property max - Maximum value or length
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const emailField: Field<string> = {
|
|
50
|
+
* value: "",
|
|
51
|
+
* error: null,
|
|
52
|
+
* touched: false,
|
|
53
|
+
* isDirty: false,
|
|
54
|
+
* required: { value: true, message: "Email is required" },
|
|
55
|
+
* pattern: {
|
|
56
|
+
* value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
57
|
+
* message: "Invalid email format"
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
type Field<T> = {
|
|
62
|
+
value: T;
|
|
63
|
+
error?: string | null;
|
|
64
|
+
touched?: boolean;
|
|
65
|
+
isDirty?: boolean;
|
|
66
|
+
required?: RequiredRule;
|
|
67
|
+
pattern?: {
|
|
68
|
+
value: RegExp;
|
|
69
|
+
message: string;
|
|
70
|
+
};
|
|
71
|
+
min?: NumberRule;
|
|
72
|
+
max?: NumberRule;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Validation resolver result containing validated values and errors.
|
|
76
|
+
* Used as return type for custom validation resolvers (Zod, Yup, etc).
|
|
77
|
+
*
|
|
78
|
+
* @template T - Type of form values
|
|
79
|
+
* @property values - Validated values if validation passes
|
|
80
|
+
* @property errors - Object containing field-level errors if validation fails
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Successful validation
|
|
84
|
+
* { values: { email: "user@example.com", age: 25 } }
|
|
85
|
+
*
|
|
86
|
+
* // Failed validation
|
|
87
|
+
* { errors: { email: "Invalid email", age: "Must be 18+" } }
|
|
88
|
+
*/
|
|
89
|
+
type ResolverResult<T extends Record<string, any>> = {
|
|
90
|
+
values?: T;
|
|
91
|
+
errors?: Partial<Record<keyof T, string>>;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Custom validation resolver function for external validation libraries.
|
|
95
|
+
* Can be synchronous or asynchronous.
|
|
96
|
+
*
|
|
97
|
+
* @template T - Type of form values
|
|
98
|
+
* @param values - Current form values to validate
|
|
99
|
+
* @returns Validation result with values or errors
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Zod resolver
|
|
103
|
+
* const schema = z.object({
|
|
104
|
+
* email: z.string().email(),
|
|
105
|
+
* password: z.string().min(8)
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* const resolver = async (values) => {
|
|
109
|
+
* const result = schema.safeParse(values);
|
|
110
|
+
* if (result.success) {
|
|
111
|
+
* return { values: result.data };
|
|
112
|
+
* }
|
|
113
|
+
* const errors = {};
|
|
114
|
+
* result.error.issues.forEach(issue => {
|
|
115
|
+
* errors[issue.path[0]] = issue.message;
|
|
116
|
+
* });
|
|
117
|
+
* return { errors };
|
|
118
|
+
* };
|
|
119
|
+
*/
|
|
120
|
+
type Resolver<T extends Record<string, any>> = (values: T) => ResolverResult<T> | Promise<ResolverResult<T>>;
|
|
121
|
+
/**
|
|
122
|
+
* Configuration parameters for form creation.
|
|
123
|
+
* Defines initial values and optional custom validation.
|
|
124
|
+
*
|
|
125
|
+
* @template T - Type of form values (must be an object)
|
|
126
|
+
* @property defaultValues - Initial field values with optional validation rules
|
|
127
|
+
* @property resolver - Optional custom validation function (Zod, Yup, etc)
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const params: HookFormParams<{ email: string; age: number }> = {
|
|
131
|
+
* defaultValues: {
|
|
132
|
+
* email: {
|
|
133
|
+
* value: "",
|
|
134
|
+
* required: { value: true, message: "Email is required" }
|
|
135
|
+
* },
|
|
136
|
+
* age: { value: 0, min: 18 }
|
|
137
|
+
* },
|
|
138
|
+
* resolver: zodResolver(schema)
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
interface HookFormParams<T extends Record<string, any>> {
|
|
142
|
+
defaultValues: {
|
|
143
|
+
[K in keyof T]: Field<T[K]> | T[K];
|
|
144
|
+
};
|
|
145
|
+
resolver?: Resolver<T>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Props for the Controller component.
|
|
149
|
+
* Configures controlled input rendering and additional input properties.
|
|
150
|
+
*
|
|
151
|
+
* @template T - Type of form values
|
|
152
|
+
* @property field - The field name being controlled
|
|
153
|
+
* @property render - Function that renders the input element with form props
|
|
154
|
+
* @property autoFocus - Auto-focus this input on mount
|
|
155
|
+
* @property onBlur - Custom callback when input loses focus
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const props: ControllerProps<FormData> = {
|
|
159
|
+
* field: "email",
|
|
160
|
+
* onBlur: () => console.log("Email field blurred"),
|
|
161
|
+
* render: (field) => (
|
|
162
|
+
* <input
|
|
163
|
+
* value={field.value}
|
|
164
|
+
* onChange={(e) => field.onChange(e.target.value)}
|
|
165
|
+
* ref={field.ref}
|
|
166
|
+
* disabled={field.disabled}
|
|
167
|
+
* />
|
|
168
|
+
* )
|
|
169
|
+
* }
|
|
170
|
+
*/
|
|
171
|
+
interface ControllerProps<T extends Record<string, any>> {
|
|
172
|
+
field: keyof T;
|
|
173
|
+
render: (field: {
|
|
174
|
+
value: any;
|
|
175
|
+
error: string;
|
|
176
|
+
onChange: (value: string) => void;
|
|
177
|
+
}) => React.ReactNode;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Creates a Zod resolver for form validation.
|
|
182
|
+
*
|
|
183
|
+
* @param schema - Zod schema object
|
|
184
|
+
* @returns A resolver function that takes values and returns { values, errors }
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const resolver = zodResolver(schema);
|
|
188
|
+
* const result = resolver({ email: 'test@test.com' });
|
|
189
|
+
* // { values: { email: 'test@test.com' } }
|
|
190
|
+
*/
|
|
191
|
+
declare const zodResolver: (schema: any) => (values: any) => {
|
|
192
|
+
values: any;
|
|
193
|
+
errors?: undefined;
|
|
194
|
+
} | {
|
|
195
|
+
errors: Record<string, string>;
|
|
196
|
+
values?: undefined;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Creates a Yup resolver for form validation.
|
|
200
|
+
*
|
|
201
|
+
* @param schema - Yup schema object
|
|
202
|
+
* @returns An async resolver function that takes values and returns { values, errors }
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* const resolver = await yupResolver(schema)(values);
|
|
206
|
+
* // { values: {...} } or { errors: {...} }
|
|
207
|
+
*/
|
|
208
|
+
declare const yupResolver: (schema: any) => (values: any) => Promise<{
|
|
209
|
+
values: any;
|
|
210
|
+
errors?: undefined;
|
|
211
|
+
} | {
|
|
212
|
+
errors: Record<string, string>;
|
|
213
|
+
values?: undefined;
|
|
214
|
+
}>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Creates a type-safe form with validation, state management, and controller components.
|
|
218
|
+
* Supports both built-in validation and custom resolvers (Zod, Yup).
|
|
219
|
+
*
|
|
220
|
+
* @template T - Form values type (must be an object)
|
|
221
|
+
* @param params - Form configuration
|
|
222
|
+
* @param params.defaultValues - Default field values with optional validation rules
|
|
223
|
+
* @param params.resolver - Optional custom validation resolver (Zod or Yup)
|
|
224
|
+
* @returns A hook function that returns form methods and Controller component
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* // Using built-in validation
|
|
228
|
+
* const form = createForm<{ email: string; age: number }>({
|
|
229
|
+
* defaultValues: {
|
|
230
|
+
* email: {
|
|
231
|
+
* value: "",
|
|
232
|
+
* required: { value: true, message: "Email is required" },
|
|
233
|
+
* pattern: { value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, message: "Invalid email" }
|
|
234
|
+
* },
|
|
235
|
+
* age: {
|
|
236
|
+
* value: 0,
|
|
237
|
+
* required: true,
|
|
238
|
+
* min: { value: 18, message: "Must be 18+" }
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* const { handleSubmit, Controller } = form();
|
|
244
|
+
*
|
|
245
|
+
* // In your component:
|
|
246
|
+
* // <form onSubmit={handleSubmit((data) => console.log(data))}>
|
|
247
|
+
* // <Controller
|
|
248
|
+
* // field="email"
|
|
249
|
+
* // render={(value, error, onChange) => (
|
|
250
|
+
* // <div>
|
|
251
|
+
* // <input value={value} onChange={(e) => onChange(e.target.value)} />
|
|
252
|
+
* // {error && <span>{error}</span>}
|
|
253
|
+
* // </div>
|
|
254
|
+
* // )}
|
|
255
|
+
* // />
|
|
256
|
+
* // </form>
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* // Using Zod resolver
|
|
260
|
+
* import { z } from 'zod';
|
|
261
|
+
* import { zodResolver } from './index';
|
|
262
|
+
*
|
|
263
|
+
* const schema = z.object({
|
|
264
|
+
* email: z.string().email("Invalid email"),
|
|
265
|
+
* password: z.string().min(8, "Min 8 characters")
|
|
266
|
+
* });
|
|
267
|
+
*
|
|
268
|
+
* const form = createForm({
|
|
269
|
+
* defaultValues: {
|
|
270
|
+
* email: "",
|
|
271
|
+
* password: ""
|
|
272
|
+
* },
|
|
273
|
+
* resolver: zodResolver(schema)
|
|
274
|
+
* });
|
|
275
|
+
*/
|
|
276
|
+
declare function createForm<T extends Record<string, any>>(params: HookFormParams<T>): () => {
|
|
277
|
+
handleSubmit: (cb: (data: T) => void) => (e: React$1.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
278
|
+
Controller: ({ field, render }: ControllerProps<T>) => React$1.ReactNode;
|
|
279
|
+
setValue: (key: keyof T, value: T[keyof T]) => void;
|
|
280
|
+
getvalues: (key?: keyof T | undefined) => void;
|
|
281
|
+
getErrors: (key?: keyof T | undefined) => string | Partial<Record<keyof T, string>>;
|
|
282
|
+
setError: (field: keyof T, error: string) => void;
|
|
283
|
+
reset: () => void;
|
|
284
|
+
watch: (key: keyof T) => T[keyof T];
|
|
285
|
+
setTouched: (field: keyof T, touched: boolean) => void;
|
|
286
|
+
isDirty: (field?: keyof T | undefined) => boolean;
|
|
287
|
+
clearAllErrors: () => void;
|
|
288
|
+
clearFieldError: (field: keyof T) => void;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export { createForm, yupResolver, zodResolver };
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Required field validation rule.
|
|
5
|
+
* Can be a simple boolean or an object with custom error message.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Simple required
|
|
9
|
+
* required: true
|
|
10
|
+
*
|
|
11
|
+
* // With custom message
|
|
12
|
+
* required: { value: true, message: "Email is required" }
|
|
13
|
+
*/
|
|
14
|
+
type RequiredRule = boolean | {
|
|
15
|
+
value: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Numeric validation rule for min/max constraints.
|
|
20
|
+
* Can be a plain number or an object with custom error message.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Simple min value
|
|
24
|
+
* min: 18
|
|
25
|
+
*
|
|
26
|
+
* // With custom message
|
|
27
|
+
* min: { value: 18, message: "Must be 18 or older" }
|
|
28
|
+
*/
|
|
29
|
+
type NumberRule = number | {
|
|
30
|
+
value: number;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Individual form field state and configuration.
|
|
35
|
+
* Tracks value, error, validation rules, and user interaction state.
|
|
36
|
+
*
|
|
37
|
+
* @template T - The type of the field value
|
|
38
|
+
*
|
|
39
|
+
* @property value - Current field value
|
|
40
|
+
* @property error - Current error message (if any)
|
|
41
|
+
* @property touched - Whether field has been focused/interacted with
|
|
42
|
+
* @property isDirty - Whether field has been modified from initial value
|
|
43
|
+
* @property required - Required validation rule
|
|
44
|
+
* @property pattern - Regex pattern for string validation
|
|
45
|
+
* @property min - Minimum value or length
|
|
46
|
+
* @property max - Maximum value or length
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const emailField: Field<string> = {
|
|
50
|
+
* value: "",
|
|
51
|
+
* error: null,
|
|
52
|
+
* touched: false,
|
|
53
|
+
* isDirty: false,
|
|
54
|
+
* required: { value: true, message: "Email is required" },
|
|
55
|
+
* pattern: {
|
|
56
|
+
* value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
57
|
+
* message: "Invalid email format"
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
type Field<T> = {
|
|
62
|
+
value: T;
|
|
63
|
+
error?: string | null;
|
|
64
|
+
touched?: boolean;
|
|
65
|
+
isDirty?: boolean;
|
|
66
|
+
required?: RequiredRule;
|
|
67
|
+
pattern?: {
|
|
68
|
+
value: RegExp;
|
|
69
|
+
message: string;
|
|
70
|
+
};
|
|
71
|
+
min?: NumberRule;
|
|
72
|
+
max?: NumberRule;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Validation resolver result containing validated values and errors.
|
|
76
|
+
* Used as return type for custom validation resolvers (Zod, Yup, etc).
|
|
77
|
+
*
|
|
78
|
+
* @template T - Type of form values
|
|
79
|
+
* @property values - Validated values if validation passes
|
|
80
|
+
* @property errors - Object containing field-level errors if validation fails
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Successful validation
|
|
84
|
+
* { values: { email: "user@example.com", age: 25 } }
|
|
85
|
+
*
|
|
86
|
+
* // Failed validation
|
|
87
|
+
* { errors: { email: "Invalid email", age: "Must be 18+" } }
|
|
88
|
+
*/
|
|
89
|
+
type ResolverResult<T extends Record<string, any>> = {
|
|
90
|
+
values?: T;
|
|
91
|
+
errors?: Partial<Record<keyof T, string>>;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Custom validation resolver function for external validation libraries.
|
|
95
|
+
* Can be synchronous or asynchronous.
|
|
96
|
+
*
|
|
97
|
+
* @template T - Type of form values
|
|
98
|
+
* @param values - Current form values to validate
|
|
99
|
+
* @returns Validation result with values or errors
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Zod resolver
|
|
103
|
+
* const schema = z.object({
|
|
104
|
+
* email: z.string().email(),
|
|
105
|
+
* password: z.string().min(8)
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* const resolver = async (values) => {
|
|
109
|
+
* const result = schema.safeParse(values);
|
|
110
|
+
* if (result.success) {
|
|
111
|
+
* return { values: result.data };
|
|
112
|
+
* }
|
|
113
|
+
* const errors = {};
|
|
114
|
+
* result.error.issues.forEach(issue => {
|
|
115
|
+
* errors[issue.path[0]] = issue.message;
|
|
116
|
+
* });
|
|
117
|
+
* return { errors };
|
|
118
|
+
* };
|
|
119
|
+
*/
|
|
120
|
+
type Resolver<T extends Record<string, any>> = (values: T) => ResolverResult<T> | Promise<ResolverResult<T>>;
|
|
121
|
+
/**
|
|
122
|
+
* Configuration parameters for form creation.
|
|
123
|
+
* Defines initial values and optional custom validation.
|
|
124
|
+
*
|
|
125
|
+
* @template T - Type of form values (must be an object)
|
|
126
|
+
* @property defaultValues - Initial field values with optional validation rules
|
|
127
|
+
* @property resolver - Optional custom validation function (Zod, Yup, etc)
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const params: HookFormParams<{ email: string; age: number }> = {
|
|
131
|
+
* defaultValues: {
|
|
132
|
+
* email: {
|
|
133
|
+
* value: "",
|
|
134
|
+
* required: { value: true, message: "Email is required" }
|
|
135
|
+
* },
|
|
136
|
+
* age: { value: 0, min: 18 }
|
|
137
|
+
* },
|
|
138
|
+
* resolver: zodResolver(schema)
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
interface HookFormParams<T extends Record<string, any>> {
|
|
142
|
+
defaultValues: {
|
|
143
|
+
[K in keyof T]: Field<T[K]> | T[K];
|
|
144
|
+
};
|
|
145
|
+
resolver?: Resolver<T>;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Props for the Controller component.
|
|
149
|
+
* Configures controlled input rendering and additional input properties.
|
|
150
|
+
*
|
|
151
|
+
* @template T - Type of form values
|
|
152
|
+
* @property field - The field name being controlled
|
|
153
|
+
* @property render - Function that renders the input element with form props
|
|
154
|
+
* @property autoFocus - Auto-focus this input on mount
|
|
155
|
+
* @property onBlur - Custom callback when input loses focus
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const props: ControllerProps<FormData> = {
|
|
159
|
+
* field: "email",
|
|
160
|
+
* onBlur: () => console.log("Email field blurred"),
|
|
161
|
+
* render: (field) => (
|
|
162
|
+
* <input
|
|
163
|
+
* value={field.value}
|
|
164
|
+
* onChange={(e) => field.onChange(e.target.value)}
|
|
165
|
+
* ref={field.ref}
|
|
166
|
+
* disabled={field.disabled}
|
|
167
|
+
* />
|
|
168
|
+
* )
|
|
169
|
+
* }
|
|
170
|
+
*/
|
|
171
|
+
interface ControllerProps<T extends Record<string, any>> {
|
|
172
|
+
field: keyof T;
|
|
173
|
+
render: (field: {
|
|
174
|
+
value: any;
|
|
175
|
+
error: string;
|
|
176
|
+
onChange: (value: string) => void;
|
|
177
|
+
}) => React.ReactNode;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Creates a Zod resolver for form validation.
|
|
182
|
+
*
|
|
183
|
+
* @param schema - Zod schema object
|
|
184
|
+
* @returns A resolver function that takes values and returns { values, errors }
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const resolver = zodResolver(schema);
|
|
188
|
+
* const result = resolver({ email: 'test@test.com' });
|
|
189
|
+
* // { values: { email: 'test@test.com' } }
|
|
190
|
+
*/
|
|
191
|
+
declare const zodResolver: (schema: any) => (values: any) => {
|
|
192
|
+
values: any;
|
|
193
|
+
errors?: undefined;
|
|
194
|
+
} | {
|
|
195
|
+
errors: Record<string, string>;
|
|
196
|
+
values?: undefined;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Creates a Yup resolver for form validation.
|
|
200
|
+
*
|
|
201
|
+
* @param schema - Yup schema object
|
|
202
|
+
* @returns An async resolver function that takes values and returns { values, errors }
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* const resolver = await yupResolver(schema)(values);
|
|
206
|
+
* // { values: {...} } or { errors: {...} }
|
|
207
|
+
*/
|
|
208
|
+
declare const yupResolver: (schema: any) => (values: any) => Promise<{
|
|
209
|
+
values: any;
|
|
210
|
+
errors?: undefined;
|
|
211
|
+
} | {
|
|
212
|
+
errors: Record<string, string>;
|
|
213
|
+
values?: undefined;
|
|
214
|
+
}>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Creates a type-safe form with validation, state management, and controller components.
|
|
218
|
+
* Supports both built-in validation and custom resolvers (Zod, Yup).
|
|
219
|
+
*
|
|
220
|
+
* @template T - Form values type (must be an object)
|
|
221
|
+
* @param params - Form configuration
|
|
222
|
+
* @param params.defaultValues - Default field values with optional validation rules
|
|
223
|
+
* @param params.resolver - Optional custom validation resolver (Zod or Yup)
|
|
224
|
+
* @returns A hook function that returns form methods and Controller component
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* // Using built-in validation
|
|
228
|
+
* const form = createForm<{ email: string; age: number }>({
|
|
229
|
+
* defaultValues: {
|
|
230
|
+
* email: {
|
|
231
|
+
* value: "",
|
|
232
|
+
* required: { value: true, message: "Email is required" },
|
|
233
|
+
* pattern: { value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, message: "Invalid email" }
|
|
234
|
+
* },
|
|
235
|
+
* age: {
|
|
236
|
+
* value: 0,
|
|
237
|
+
* required: true,
|
|
238
|
+
* min: { value: 18, message: "Must be 18+" }
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* const { handleSubmit, Controller } = form();
|
|
244
|
+
*
|
|
245
|
+
* // In your component:
|
|
246
|
+
* // <form onSubmit={handleSubmit((data) => console.log(data))}>
|
|
247
|
+
* // <Controller
|
|
248
|
+
* // field="email"
|
|
249
|
+
* // render={(value, error, onChange) => (
|
|
250
|
+
* // <div>
|
|
251
|
+
* // <input value={value} onChange={(e) => onChange(e.target.value)} />
|
|
252
|
+
* // {error && <span>{error}</span>}
|
|
253
|
+
* // </div>
|
|
254
|
+
* // )}
|
|
255
|
+
* // />
|
|
256
|
+
* // </form>
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* // Using Zod resolver
|
|
260
|
+
* import { z } from 'zod';
|
|
261
|
+
* import { zodResolver } from './index';
|
|
262
|
+
*
|
|
263
|
+
* const schema = z.object({
|
|
264
|
+
* email: z.string().email("Invalid email"),
|
|
265
|
+
* password: z.string().min(8, "Min 8 characters")
|
|
266
|
+
* });
|
|
267
|
+
*
|
|
268
|
+
* const form = createForm({
|
|
269
|
+
* defaultValues: {
|
|
270
|
+
* email: "",
|
|
271
|
+
* password: ""
|
|
272
|
+
* },
|
|
273
|
+
* resolver: zodResolver(schema)
|
|
274
|
+
* });
|
|
275
|
+
*/
|
|
276
|
+
declare function createForm<T extends Record<string, any>>(params: HookFormParams<T>): () => {
|
|
277
|
+
handleSubmit: (cb: (data: T) => void) => (e: React$1.FormEvent<HTMLFormElement>) => Promise<void>;
|
|
278
|
+
Controller: ({ field, render }: ControllerProps<T>) => React$1.ReactNode;
|
|
279
|
+
setValue: (key: keyof T, value: T[keyof T]) => void;
|
|
280
|
+
getvalues: (key?: keyof T | undefined) => void;
|
|
281
|
+
getErrors: (key?: keyof T | undefined) => string | Partial<Record<keyof T, string>>;
|
|
282
|
+
setError: (field: keyof T, error: string) => void;
|
|
283
|
+
reset: () => void;
|
|
284
|
+
watch: (key: keyof T) => T[keyof T];
|
|
285
|
+
setTouched: (field: keyof T, touched: boolean) => void;
|
|
286
|
+
isDirty: (field?: keyof T | undefined) => boolean;
|
|
287
|
+
clearAllErrors: () => void;
|
|
288
|
+
clearFieldError: (field: keyof T) => void;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export { createForm, yupResolver, zodResolver };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var g=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var D=(t,s)=>{for(var a in s)g(t,a,{get:s[a],enumerable:!0})},M=(t,s,a,i)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of j(s))!C.call(t,c)&&c!==a&&g(t,c,{get:()=>s[c],enumerable:!(i=w(s,c))||i.enumerable});return t};var q=t=>M(g({},"__esModule",{value:!0}),t);var A={};D(A,{createForm:()=>z,yupResolver:()=>F,zodResolver:()=>R});module.exports=q(A);var b=require("react");function S(t,s=[]){let a,i=[],c=e=>{let o=typeof e=="function"?e(a):e;a={...a,...o},i.forEach(r=>r())},p=()=>a,f=N(c,p,s);a=t(f,p);let y=e=>(i.push(e),()=>{i=i.filter(o=>o!==e)});return(e=o=>o)=>(0,b.useSyncExternalStore)(y,()=>e(a))}var N=(t,s,a)=>!a||a.length===0?t:a.reduceRight((i,c)=>c(t,s)(i),t);function O(t){return t.charAt(0).toUpperCase()+t.slice(1)}function E(t,s){return t?typeof t=="boolean"?{value:t,message:t?`${O(s)} is required`:""}:t:{value:!1,message:""}}function h(t,s){return t===void 0?null:typeof t=="number"?{value:t,message:s==="min"?`Minimum is ${t}`:`Maximum is ${t}`}:t}function v(t){let s={};return Object.keys(t||{}).forEach(a=>{let i=t[a];typeof i=="object"&&"value"in i&&(s[a]=i.value)}),s}var R=t=>s=>{let a=t.safeParse(s);if(a.success)return{values:a.data};let i={};return a.error.issues.forEach(c=>{let p=c.path[0];i[p]=c.message}),{errors:i}},F=t=>async s=>{try{return{values:await t.validate(s,{abortEarly:!1})}}catch(a){let i={};return a.inner.forEach(c=>{i[c.path]=c.message}),{errors:i}}};function V(t){let s={};return Object.keys(t).forEach(a=>{let i=t[a];i&&typeof i=="object"&&"value"in i?s[a]={error:"",...i}:s[a]={value:i,error:""}}),s}function k(t,s){if(typeof s=="number"){let a=Number(t);return isNaN(a)?0:a}return typeof s=="boolean"?!!t:t}function z(t){let{defaultValues:s,resolver:a}=t,i=V(s),c=S((f,y)=>({...i,setFieldValue:(e,o)=>{var n;let r=y()[e];f({[e]:{...r,value:k(o,(n=i[e])==null?void 0:n.value)}})},defaultValidateField:e=>{let r=y()[e],n="",u=k(r.value,r.value),T=E(r.required,String(e)),d=h(r.min,"min"),m=h(r.max,"max");return T.value&&!u?n=T.message:typeof u=="string"&&r.pattern&&!r.pattern.value.test(u)?n=r.pattern.message:d&&(typeof u=="string"&&u.length<d.value||typeof u=="number"&&u<d.value)?n=d.message:m&&(typeof u=="string"&&u.length>m.value||typeof u=="number"&&u>m.value)&&(n=m.message),f({[e]:{...r,error:n}}),n},resolverValidate:async e=>{if(!a)return;let o=y(),r=o[e],n="",u=v(o),T=await a(u);if(T!=null&&T.errors){let d=T.errors[e];d&&(n=d)}return f({[e]:{...r,error:n}}),n},handleSubmit:e=>async o=>{o.preventDefault();let r=!1,n=y(),u=v(n),T=Object.keys(u);if(a){for(let d of T)await n.resolverValidate(d)&&(r=!0);r||e(u);return}for(let d of T)n.defaultValidateField(d)&&(r=!0);r||e(u)},getvalues:e=>e?y()[e].value:v(e),setValue:(e,o)=>{f({[e]:{...y()[e],value:o}})},setError:(e,o)=>{let r=y()[e];f({[e]:{...r,error:o}})},getErrors:e=>{let o=y();if(e){let n=o[e];return(n==null?void 0:n.error)||""}let r={};return Object.keys(o).forEach(n=>{let u=o[n];u.error&&(r[n]=u.error)}),r},clearFieldError:e=>{let o=y()[e];f({[e]:{...o,error:""}})},clearAllErrors:()=>{let e=y(),o={};Object.keys(e).forEach(r=>{let n=e[r];o[r]={...n,error:""}}),f(o)},isDirty:e=>{let o=y();if(e){let r=o[e];return(r==null?void 0:r.isDirty)||!1}return Object.keys(o).some(r=>o[r].isDirty)},isTouched:e=>{let r=y()[e];return(r==null?void 0:r.touched)||!1},setTouched:(e,o)=>{let r=y()[e];f({[e]:{...r,touched:o}})},reset:()=>{let e={};Object.keys(i).forEach(o=>{e[o]={...i[o],error:"",touched:!1,isDirty:!1}}),f(e)}}));function p({field:f,render:y}){let e=c(),o=e[f].value,r=e[f].error,n=e.setFieldValue,u=e.defaultValidateField,T=e.resolverValidate,d=e.setTouched;return y({error:r||"",onChange:async l=>{n(f,l),d(f,!0),a?await T(f):u(f)},value:o})}return()=>{let f=c(l=>l.handleSubmit),y=c(l=>l.setValue),e=c(l=>l.getvalues),o=c(l=>l.getErrors),r=c(l=>l.setError),n=c(l=>l.reset),u=c(l=>l.setTouched),T=c(l=>l.isDirty),d=c(l=>l.clearAllErrors),m=c(l=>l.clearFieldError);return{handleSubmit:f,Controller:p,setValue:y,getvalues:e,getErrors:o,setError:r,reset:n,watch:l=>c(P=>P[l].value),setTouched:u,isDirty:T,clearAllErrors:d,clearFieldError:m}}}0&&(module.exports={createForm,yupResolver,zodResolver});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as h}from"../chunk-RXPCG2VZ.mjs";function V(o){return o.charAt(0).toUpperCase()+o.slice(1)}function b(o,u){return o?typeof o=="boolean"?{value:o,message:o?`${V(u)} is required`:""}:o:{value:!1,message:""}}function g(o,u){return o===void 0?null:typeof o=="number"?{value:o,message:u==="min"?`Minimum is ${o}`:`Maximum is ${o}`}:o}function v(o){let u={};return Object.keys(o||{}).forEach(i=>{let c=o[i];typeof c=="object"&&"value"in c&&(u[i]=c.value)}),u}var x=o=>u=>{let i=o.safeParse(u);if(i.success)return{values:i.data};let c={};return i.error.issues.forEach(l=>{let p=l.path[0];c[p]=l.message}),{errors:c}},S=o=>async u=>{try{return{values:await o.validate(u,{abortEarly:!1})}}catch(i){let c={};return i.inner.forEach(l=>{c[l.path]=l.message}),{errors:c}}};function E(o){let u={};return Object.keys(o).forEach(i=>{let c=o[i];c&&typeof c=="object"&&"value"in c?u[i]={error:"",...c}:u[i]={value:c,error:""}}),u}function k(o,u){if(typeof u=="number"){let i=Number(o);return isNaN(i)?0:i}return typeof u=="boolean"?!!o:o}function w(o){let{defaultValues:u,resolver:i}=o,c=E(u),l=h((f,y)=>({...c,setFieldValue:(e,t)=>{var s;let r=y()[e];f({[e]:{...r,value:k(t,(s=c[e])==null?void 0:s.value)}})},defaultValidateField:e=>{let r=y()[e],s="",a=k(r.value,r.value),m=b(r.required,String(e)),d=g(r.min,"min"),T=g(r.max,"max");return m.value&&!a?s=m.message:typeof a=="string"&&r.pattern&&!r.pattern.value.test(a)?s=r.pattern.message:d&&(typeof a=="string"&&a.length<d.value||typeof a=="number"&&a<d.value)?s=d.message:T&&(typeof a=="string"&&a.length>T.value||typeof a=="number"&&a>T.value)&&(s=T.message),f({[e]:{...r,error:s}}),s},resolverValidate:async e=>{if(!i)return;let t=y(),r=t[e],s="",a=v(t),m=await i(a);if(m!=null&&m.errors){let d=m.errors[e];d&&(s=d)}return f({[e]:{...r,error:s}}),s},handleSubmit:e=>async t=>{t.preventDefault();let r=!1,s=y(),a=v(s),m=Object.keys(a);if(i){for(let d of m)await s.resolverValidate(d)&&(r=!0);r||e(a);return}for(let d of m)s.defaultValidateField(d)&&(r=!0);r||e(a)},getvalues:e=>e?y()[e].value:v(e),setValue:(e,t)=>{f({[e]:{...y()[e],value:t}})},setError:(e,t)=>{let r=y()[e];f({[e]:{...r,error:t}})},getErrors:e=>{let t=y();if(e){let s=t[e];return(s==null?void 0:s.error)||""}let r={};return Object.keys(t).forEach(s=>{let a=t[s];a.error&&(r[s]=a.error)}),r},clearFieldError:e=>{let t=y()[e];f({[e]:{...t,error:""}})},clearAllErrors:()=>{let e=y(),t={};Object.keys(e).forEach(r=>{let s=e[r];t[r]={...s,error:""}}),f(t)},isDirty:e=>{let t=y();if(e){let r=t[e];return(r==null?void 0:r.isDirty)||!1}return Object.keys(t).some(r=>t[r].isDirty)},isTouched:e=>{let r=y()[e];return(r==null?void 0:r.touched)||!1},setTouched:(e,t)=>{let r=y()[e];f({[e]:{...r,touched:t}})},reset:()=>{let e={};Object.keys(c).forEach(t=>{e[t]={...c[t],error:"",touched:!1,isDirty:!1}}),f(e)}}));function p({field:f,render:y}){let e=l(),t=e[f].value,r=e[f].error,s=e.setFieldValue,a=e.defaultValidateField,m=e.resolverValidate,d=e.setTouched;return y({error:r||"",onChange:async n=>{s(f,n),d(f,!0),i?await m(f):a(f)},value:t})}return()=>{let f=l(n=>n.handleSubmit),y=l(n=>n.setValue),e=l(n=>n.getvalues),t=l(n=>n.getErrors),r=l(n=>n.setError),s=l(n=>n.reset),a=l(n=>n.setTouched),m=l(n=>n.isDirty),d=l(n=>n.clearAllErrors),T=l(n=>n.clearFieldError);return{handleSubmit:f,Controller:p,setValue:y,getvalues:e,getErrors:t,setError:r,reset:s,watch:n=>l(F=>F[n].value),setTouched:a,isDirty:m,clearAllErrors:d,clearFieldError:T}}}export{w as createForm,S as yupResolver,x as zodResolver};
|
package/dist/i18n/index.d.mts
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
interface I18nParams<T, L> {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
initialLan: L;
|
|
3
|
+
resource: (lan: L) => Promise<T> | T;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Recursively gets all nested keys from object using dot notation.
|
|
8
7
|
* Safely handles deep nesting without infinite recursion.
|
|
9
8
|
*/
|
|
10
|
-
type Join<K extends string | number, P extends string | number> =
|
|
11
|
-
`${K}${'' extends P ? '' : `.${P}` }`;
|
|
12
|
-
|
|
9
|
+
type Join<K extends string | number, P extends string | number> = `${K}${'' extends P ? '' : `.${P}`}`;
|
|
13
10
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
T extends object
|
|
18
|
-
? {
|
|
19
|
-
[K in keyof T]-?: K extends string
|
|
20
|
-
? T[K] extends (infer U)[]
|
|
21
|
-
? K
|
|
22
|
-
: T[K] extends object
|
|
23
|
-
? K | Join<K, NestedKeys<T[K], Prev[D]>>
|
|
24
|
-
: K
|
|
25
|
-
: never
|
|
26
|
-
}[keyof T & string]
|
|
27
|
-
: never;
|
|
28
|
-
|
|
11
|
+
type NestedKeys<T, D extends number = 9> = D extends never ? never : T extends object ? {
|
|
12
|
+
[K in keyof T]-?: K extends string ? T[K] extends (infer U)[] ? K : T[K] extends object ? K | Join<K, NestedKeys<T[K], Prev[D]>> : K : never;
|
|
13
|
+
}[keyof T & string] : never;
|
|
29
14
|
type TranslationKey<T> = NestedKeys<T> & string;
|
|
30
15
|
|
|
31
|
-
declare function
|
|
16
|
+
declare function createI18n<T = any, L = any>(params: I18nParams<T, L>): () => {
|
|
32
17
|
t: (key: TranslationKey<T>) => string;
|
|
33
18
|
lan: L;
|
|
34
19
|
updateTranslation: (lang: L) => void;
|
|
@@ -36,4 +21,4 @@ declare function create<T = any, L = any>(params: I18nParams<T, L>): () => {
|
|
|
36
21
|
isInitialLoading: boolean;
|
|
37
22
|
};
|
|
38
23
|
|
|
39
|
-
export {
|
|
24
|
+
export { createI18n };
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
interface I18nParams<T, L> {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
initialLan: L;
|
|
3
|
+
resource: (lan: L) => Promise<T> | T;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Recursively gets all nested keys from object using dot notation.
|
|
8
7
|
* Safely handles deep nesting without infinite recursion.
|
|
9
8
|
*/
|
|
10
|
-
type Join<K extends string | number, P extends string | number> =
|
|
11
|
-
`${K}${'' extends P ? '' : `.${P}` }`;
|
|
12
|
-
|
|
9
|
+
type Join<K extends string | number, P extends string | number> = `${K}${'' extends P ? '' : `.${P}`}`;
|
|
13
10
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...0[]];
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
T extends object
|
|
18
|
-
? {
|
|
19
|
-
[K in keyof T]-?: K extends string
|
|
20
|
-
? T[K] extends (infer U)[]
|
|
21
|
-
? K
|
|
22
|
-
: T[K] extends object
|
|
23
|
-
? K | Join<K, NestedKeys<T[K], Prev[D]>>
|
|
24
|
-
: K
|
|
25
|
-
: never
|
|
26
|
-
}[keyof T & string]
|
|
27
|
-
: never;
|
|
28
|
-
|
|
11
|
+
type NestedKeys<T, D extends number = 9> = D extends never ? never : T extends object ? {
|
|
12
|
+
[K in keyof T]-?: K extends string ? T[K] extends (infer U)[] ? K : T[K] extends object ? K | Join<K, NestedKeys<T[K], Prev[D]>> : K : never;
|
|
13
|
+
}[keyof T & string] : never;
|
|
29
14
|
type TranslationKey<T> = NestedKeys<T> & string;
|
|
30
15
|
|
|
31
|
-
declare function
|
|
16
|
+
declare function createI18n<T = any, L = any>(params: I18nParams<T, L>): () => {
|
|
32
17
|
t: (key: TranslationKey<T>) => string;
|
|
33
18
|
lan: L;
|
|
34
19
|
updateTranslation: (lang: L) => void;
|
|
@@ -36,4 +21,4 @@ declare function create<T = any, L = any>(params: I18nParams<T, L>): () => {
|
|
|
36
21
|
isInitialLoading: boolean;
|
|
37
22
|
};
|
|
38
23
|
|
|
39
|
-
export {
|
|
24
|
+
export { createI18n };
|
package/dist/i18n/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var c=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var M=(e,a)=>{for(var t in a)c(e,t,{get:a[t],enumerable:!0})},x=(e,a,t,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of h(a))!w.call(e,i)&&i!==t&&c(e,i,{get:()=>a[i],enumerable:!(n=U(a,i))||n.enumerable});return e};var b=e=>x(c({},"__esModule",{value:!0}),e);var C={};M(C,{
|
|
1
|
+
"use strict";"use client";var c=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var M=(e,a)=>{for(var t in a)c(e,t,{get:a[t],enumerable:!0})},x=(e,a,t,n)=>{if(a&&typeof a=="object"||typeof a=="function")for(let i of h(a))!w.call(e,i)&&i!==t&&c(e,i,{get:()=>a[i],enumerable:!(n=U(a,i))||n.enumerable});return e};var b=e=>x(c({},"__esModule",{value:!0}),e);var C={};M(C,{createI18n:()=>E});module.exports=b(C);var m=require("react");function S(e,a=[]){let t,n=[],i=r=>{let s=typeof r=="function"?r(t):r;t={...t,...s},n.forEach(d=>d())},l=()=>t,u=v(i,l,a);t=e(u,l);let o=r=>(n.push(r),()=>{n=n.filter(s=>s!==r)});return(r=s=>s)=>(0,m.useSyncExternalStore)(o,()=>r(t))}var v=(e,a,t)=>!t||t.length===0?e:t.reduceRight((n,i)=>i(e,a)(n),e);var y=require("react");function E(e){let{resource:a,initialLan:t}=e,n=0,i=S((l,u)=>({lan:t,data:null,isUpdating:!1,isInitialLoading:!0,async load(o){let r=++n,s=u().data===null;l({isUpdating:!s,isInitialLoading:s});let d=await Promise.resolve(a(o));r===n&&l({data:d,isUpdating:!1,isInitialLoading:!1})},update(o){l({lan:o})}}));return function(){let{lan:u,data:o,update:r,isUpdating:s,isInitialLoading:d,load:L}=i();(0,y.useEffect)(()=>{L(u)},[u]);function g(p){var f;return!o||d?"":(f=p.split(".").reduce((T,I)=>T==null?void 0:T[I],o))!=null?f:p}function P(p){r(p)}return{t:g,lan:u,updateTranslation:P,isUpdating:s,isInitialLoading:d}}}0&&(module.exports={createI18n});
|
package/dist/i18n/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a as d}from"../chunk-RXPCG2VZ.mjs";import{useEffect as I}from"react";function S(p){let{resource:f,initialLan:L}=p,l=0,T=d((a,
|
|
1
|
+
"use client";import{a as d}from"../chunk-RXPCG2VZ.mjs";import{useEffect as I}from"react";function S(p){let{resource:f,initialLan:L}=p,l=0,T=d((a,t)=>({lan:L,data:null,isUpdating:!1,isInitialLoading:!0,async load(n){let s=++l,i=t().data===null;a({isUpdating:!i,isInitialLoading:i});let e=await Promise.resolve(f(n));s===l&&a({data:e,isUpdating:!1,isInitialLoading:!1})},update(n){a({lan:n})}}));return function(){let{lan:t,data:n,update:s,isUpdating:i,isInitialLoading:e,load:c}=T();I(()=>{c(t)},[t]);function g(r){var u;return!n||e?"":(u=r.split(".").reduce((o,y)=>o==null?void 0:o[y],n))!=null?u:r}function m(r){s(r)}return{t:g,lan:t,updateTranslation:m,isUpdating:i,isInitialLoading:e}}}export{S as createI18n};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zustic",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A fast, minimal state management solution for React ecosystems. Works seamlessly with React, Next.js, and React Native, offering predictable state updates with a tiny footprint.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"types": "./dist/i18n/index.d.ts",
|
|
22
22
|
"import": "./dist/i18n/index.mjs",
|
|
23
23
|
"require": "./dist/i18n/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./hook-form": {
|
|
26
|
+
"types": "./dist/hook-form/index.d.ts",
|
|
27
|
+
"import": "./dist/hook-form/index.mjs",
|
|
28
|
+
"require": "./dist/hook-form/index.js"
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"directories": {
|