@faasjs/react 8.0.0-beta.5 → 8.0.0-beta.7

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/index.d.ts CHANGED
@@ -1,46 +1,114 @@
1
- import { Response, BaseUrl, Options, ResponseError, FaasBrowserClient } from '@faasjs/browser';
2
- export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
3
- import { FaasActionUnionType, FaasAction, FaasParams, FaasData } from '@faasjs/types';
4
- export { FaasAction, FaasActionUnionType, FaasData, FaasParams } from '@faasjs/types';
5
- import * as react from 'react';
6
- import { JSX, Component, ReactNode, ReactElement, ComponentType, JSXElementConstructor, ComponentProps, Dispatch, SetStateAction, RefObject } from 'react';
7
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import { BaseUrl, FaasBrowserClient, Options, Options as Options$1, Response, Response as Response$1, ResponseError, ResponseError as ResponseError$1, ResponseHeaders } from "@faasjs/browser";
2
+ import * as react from "react";
3
+ import { Component, ComponentProps, ComponentType, Dispatch, ErrorInfo, JSX, JSXElementConstructor, ReactElement, ReactNode, RefObject, SetStateAction } from "react";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
8
5
 
6
+ //#region ../types/src/index.d.ts
7
+ /**
8
+ * Interface for defining FaasJS actions.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * declare module '@faasjs/types' {
13
+ * interface FaasActions {
14
+ * demo: {
15
+ * Params: {
16
+ * key: string
17
+ * }
18
+ * Data: {
19
+ * value: string
20
+ * }
21
+ * }
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ interface FaasActions {
27
+ /**
28
+ * Internal placeholder to keep this interface visible in generated docs.
29
+ */
30
+ faasjsActionsPlaceholder?: {
31
+ Params: Record<string, any>;
32
+ Data: Record<string, any>;
33
+ };
34
+ }
35
+ /**
36
+ * Infer all action paths declared in {@link FaasActions}.
37
+ */
38
+ type FaasActionPaths = Exclude<Extract<keyof FaasActions, string>, 'faasjsActionsPlaceholder'>;
39
+ /**
40
+ * Union type accepted by action helpers.
41
+ */
42
+ type FaasActionUnionType = FaasActionPaths | Record<string, any> | string;
43
+ /**
44
+ * Infer the action path type.
45
+ *
46
+ * Returns the original type when `T` is a known action path,
47
+ * otherwise falls back to `string`.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * type A = FaasAction<'demo'> // 'demo'
52
+ * type B = FaasAction<number> // string
53
+ * ```
54
+ */
55
+ type FaasAction<T = any> = T extends FaasActionPaths ? T : string;
56
+ /**
57
+ * Infer params type by action path.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * type DemoParams = FaasParams<'demo'>
62
+ * ```
63
+ */
64
+ type FaasParams<T = any> = T extends FaasActionPaths ? FaasActions[T]['Params'] : Record<string, any>;
65
+ /**
66
+ * Infer response data type by action path.
67
+ *
68
+ * If `T` is already a plain object type, it is returned directly.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * type DemoData = FaasData<'demo'>
73
+ * type CustomData = FaasData<{ value: number }> // { value: number }
74
+ * ```
75
+ */
76
+ type FaasData<T = any> = T extends FaasActionPaths ? FaasActions[T]['Data'] : T extends Record<string, any> ? T : Record<string, any>;
77
+ //#endregion
78
+ //#region src/FaasDataWrapper.d.ts
9
79
  /**
10
80
  * Injects FaasData props.
11
81
  */
12
82
  type FaasDataInjection<PathOrData extends FaasActionUnionType = any> = {
13
- action: FaasAction<PathOrData>;
14
- params: FaasParams<PathOrData>;
15
- loading: boolean;
16
- reloadTimes: number;
17
- data: FaasData<PathOrData>;
18
- error: any;
19
- promise: Promise<Response<FaasData<PathOrData>>>;
20
- /**
21
- * Reloads data with new or existing parameters.
22
- *
23
- * **Note**: It will sets skip to false before loading data.
24
- */
25
- reload(params?: Record<string, any>): Promise<FaasData<PathOrData>>;
26
- setData: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
27
- setLoading: React.Dispatch<React.SetStateAction<boolean>>;
28
- setPromise: React.Dispatch<React.SetStateAction<Promise<Response<FaasData<PathOrData>>>>>;
29
- setError: React.Dispatch<React.SetStateAction<any>>;
83
+ action: FaasAction<PathOrData>;
84
+ params: FaasParams<PathOrData>;
85
+ loading: boolean;
86
+ reloadTimes: number;
87
+ data: FaasData<PathOrData>;
88
+ error: any;
89
+ promise: Promise<Response$1<FaasData<PathOrData>>>;
90
+ /**
91
+ * Reloads data with new or existing parameters.
92
+ *
93
+ * **Note**: It will sets skip to false before loading data.
94
+ */
95
+ reload(params?: Record<string, any>): Promise<FaasData<PathOrData>>;
96
+ setData: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
97
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
98
+ setPromise: React.Dispatch<React.SetStateAction<Promise<Response$1<FaasData<PathOrData>>>>>;
99
+ setError: React.Dispatch<React.SetStateAction<any>>;
30
100
  };
31
101
  type FaasDataWrapperProps<PathOrData extends FaasActionUnionType> = {
32
- render?(args: FaasDataInjection<PathOrData>): JSX.Element | JSX.Element[];
33
- children?: React.ReactElement<Partial<FaasDataInjection<PathOrData>>>;
34
- fallback?: JSX.Element | false;
35
- action: FaasAction<PathOrData>;
36
- params?: FaasParams<PathOrData>;
37
- onDataChange?(args: FaasDataInjection<PathOrData>): void;
38
- /** use custom data, should work with setData */
39
- data?: FaasData<PathOrData>;
40
- /** use custom setData, should work with data */
41
- setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
42
- baseUrl?: BaseUrl;
43
- ref?: React.Ref<FaasDataWrapperRef<PathOrData>>;
102
+ render?(args: FaasDataInjection<PathOrData>): JSX.Element | JSX.Element[];
103
+ children?: React.ReactElement<Partial<FaasDataInjection<PathOrData>>>;
104
+ fallback?: JSX.Element | false;
105
+ action: FaasAction<PathOrData>;
106
+ params?: FaasParams<PathOrData>;
107
+ onDataChange?(args: FaasDataInjection<PathOrData>): void; /** use custom data, should work with setData */
108
+ data?: FaasData<PathOrData>; /** use custom setData, should work with data */
109
+ setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
110
+ baseUrl?: BaseUrl;
111
+ ref?: React.Ref<FaasDataWrapperRef<PathOrData>>;
44
112
  };
45
113
  type FaasDataWrapperRef<PathOrData extends FaasActionUnionType = any> = FaasDataInjection<PathOrData>;
46
114
  declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType = any>(props: FaasDataWrapperProps<PathOrData> & react.RefAttributes<FaasDataWrapperRef<PathOrData>>) => React.ReactElement | null;
@@ -53,7 +121,8 @@ declare const FaasDataWrapper: <PathOrData extends FaasActionUnionType = any>(pr
53
121
  * ```
54
122
  */
55
123
  declare function withFaasData<PathOrData extends FaasActionUnionType, TComponentProps extends Required<FaasDataInjection<PathOrData>> = Required<FaasDataInjection<PathOrData>>>(Component: React.FC<TComponentProps>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection<PathOrData>> & Record<string, any>>;
56
-
124
+ //#endregion
125
+ //#region src/faas.d.ts
57
126
  /**
58
127
  * Request faas server
59
128
  *
@@ -68,21 +137,21 @@ declare function withFaasData<PathOrData extends FaasActionUnionType, TComponent
68
137
  * })
69
138
  * ```
70
139
  */
71
- declare function faas<PathOrData extends FaasActionUnionType>(action: FaasAction<PathOrData>, params: FaasParams<PathOrData>, options?: Options): Promise<Response<FaasData<PathOrData>>>;
72
-
140
+ declare function faas<PathOrData extends FaasActionUnionType>(action: FaasAction<PathOrData>, params: FaasParams<PathOrData>, options?: Options$1): Promise<Response$1<FaasData<PathOrData>>>;
141
+ //#endregion
142
+ //#region src/useFaas.d.ts
73
143
  type useFaasOptions<PathOrData extends FaasActionUnionType> = {
74
- params?: FaasParams<PathOrData>;
75
- data?: FaasData<PathOrData>;
76
- setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
77
- /**
78
- * If skip is true, the request will not be sent.
79
- *
80
- * However, you can still use reload to send the request.
81
- */
82
- skip?: boolean | ((params: FaasParams<PathOrData>) => boolean);
83
- /** Send the last request after milliseconds */
84
- debounce?: number;
85
- baseUrl?: BaseUrl;
144
+ params?: FaasParams<PathOrData>;
145
+ data?: FaasData<PathOrData>;
146
+ setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
147
+ /**
148
+ * If skip is true, the request will not be sent.
149
+ *
150
+ * However, you can still use reload to send the request.
151
+ */
152
+ skip?: boolean | ((params: FaasParams<PathOrData>) => boolean); /** Send the last request after milliseconds */
153
+ debounce?: number;
154
+ baseUrl?: BaseUrl;
86
155
  };
87
156
  /**
88
157
  * Request faas server with React hook
@@ -100,36 +169,34 @@ type useFaasOptions<PathOrData extends FaasActionUnionType> = {
100
169
  * ```
101
170
  */
102
171
  declare function useFaas<PathOrData extends FaasActionUnionType>(action: FaasAction<PathOrData>, defaultParams: FaasParams<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<PathOrData>;
103
-
104
- type OnError = (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
172
+ //#endregion
173
+ //#region src/client.d.ts
174
+ type OnError = (action: string, params: Record<string, any>) => (res: ResponseError$1) => Promise<void>;
105
175
  type FaasReactClientOptions = {
106
- /** @default `/` */
107
- baseUrl?: BaseUrl;
108
- options?: Options;
109
- /**
110
- * @example
111
- * ```ts
112
- * onError: (action, params) => async (res) => {
113
- * console.error(action, params, res)
114
- * }
115
- * ```
116
- */
117
- onError?: OnError;
176
+ /** @default `/` */baseUrl?: BaseUrl;
177
+ options?: Options$1;
178
+ /**
179
+ * @example
180
+ * ```ts
181
+ * onError: (action, params) => async (res) => {
182
+ * console.error(action, params, res)
183
+ * }
184
+ * ```
185
+ */
186
+ onError?: OnError;
118
187
  };
119
188
  type FaasReactClientInstance = {
120
- id: string;
121
- faas: typeof faas;
122
- useFaas: typeof useFaas;
123
- FaasDataWrapper: typeof FaasDataWrapper;
124
- onError?: OnError;
125
- browserClient: FaasBrowserClient;
189
+ id: string;
190
+ faas: typeof faas;
191
+ useFaas: typeof useFaas;
192
+ FaasDataWrapper: typeof FaasDataWrapper;
193
+ onError?: OnError;
194
+ browserClient: FaasBrowserClient;
126
195
  };
127
196
  /**
128
197
  * Before use faas, you should initialize a FaasReactClient.
129
198
  *
130
- * @param props.baseUrl {string} The baseUrl of your faas server
131
- * @param props.options {Options} The options of client
132
- * @returns {FaasReactClientInstance}
199
+ * @returns FaasReactClient instance.
133
200
  *
134
201
  * @example
135
202
  * ```ts
@@ -138,7 +205,11 @@ type FaasReactClientInstance = {
138
205
  * })
139
206
  * ```
140
207
  */
141
- declare function FaasReactClient({ baseUrl, options, onError }?: FaasReactClientOptions): FaasReactClientInstance;
208
+ declare function FaasReactClient({
209
+ baseUrl,
210
+ options: clientOptions,
211
+ onError
212
+ }?: FaasReactClientOptions): FaasReactClientInstance;
142
213
  /**
143
214
  * Get FaasReactClient instance
144
215
  *
@@ -153,35 +224,36 @@ declare function FaasReactClient({ baseUrl, options, onError }?: FaasReactClient
153
224
  * ```
154
225
  */
155
226
  declare function getClient(host?: string): FaasReactClientInstance;
156
-
227
+ //#endregion
228
+ //#region src/constant.d.ts
157
229
  /**
158
230
  * Returns a constant value that is created by the given function.
159
231
  */
160
232
  declare function useConstant<T>(fn: () => T): T;
161
-
233
+ //#endregion
234
+ //#region src/ErrorBoundary.d.ts
162
235
  interface ErrorBoundaryProps {
163
- children?: ReactNode;
164
- onError?: (error: Error | null, info: any) => void;
165
- errorChildren?: ReactElement<ErrorChildrenProps>;
236
+ children?: ReactNode;
237
+ onError?: (error: Error | null, info: any) => void;
238
+ errorChildren?: ReactElement<ErrorChildrenProps>;
166
239
  }
167
240
  type ErrorChildrenProps = {
168
- error?: Error;
169
- info?: any;
170
- errorMessage?: string;
171
- errorDescription?: string;
241
+ error?: Error;
242
+ info?: any;
243
+ errorMessage?: string;
244
+ errorDescription?: string;
172
245
  };
173
246
  declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
174
- error?: Error;
175
- info?: {
176
- componentStack?: string;
177
- };
247
+ error: Error | null;
248
+ info: ErrorInfo;
178
249
  }> {
179
- static displayName: string;
180
- constructor(props: ErrorBoundaryProps);
181
- componentDidCatch(error: Error | null, info: any): void;
182
- render(): string | number | bigint | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode>>;
250
+ static displayName: string;
251
+ constructor(props: ErrorBoundaryProps);
252
+ componentDidCatch(error: Error, info: ErrorInfo): void;
253
+ render(): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
183
254
  }
184
-
255
+ //#endregion
256
+ //#region src/equal.d.ts
185
257
  /**
186
258
  * Compares two values for deep equality.
187
259
  *
@@ -225,7 +297,8 @@ declare function useEqualMemo<T>(callback: () => T, dependencies: any[]): T;
225
297
  * @returns The result of the `useCallback` hook with memoized dependencies.
226
298
  */
227
299
  declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T, dependencies: any[]): T;
228
-
300
+ //#endregion
301
+ //#region src/Form/elements/Button.d.ts
229
302
  /**
230
303
  * Props for the FormButtonElement component.
231
304
  *
@@ -234,11 +307,12 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
234
307
  * @property {() => Promise<void>} submit - A function to be called when the button is clicked, which returns a promise.
235
308
  */
236
309
  type FormButtonElementProps = {
237
- children?: React.ReactNode;
238
- submitting: boolean;
239
- submit: () => Promise<void>;
310
+ children?: React.ReactNode;
311
+ submitting: boolean;
312
+ submit: () => Promise<void>;
240
313
  };
241
-
314
+ //#endregion
315
+ //#region src/Form/elements/Input.d.ts
242
316
  /**
243
317
  * Props for the Form Input Element component.
244
318
  *
@@ -247,11 +321,12 @@ type FormButtonElementProps = {
247
321
  * @property {(value: any) => void} onChange - Callback function to handle changes to the input value.
248
322
  */
249
323
  type FormInputElementProps = {
250
- name: string;
251
- value: any;
252
- onChange: (value: any) => void;
324
+ name: string;
325
+ value: any;
326
+ onChange: (value: any) => void;
253
327
  };
254
-
328
+ //#endregion
329
+ //#region src/Form/elements/Label.d.ts
255
330
  /**
256
331
  * Props for the FormLabelElement component.
257
332
  *
@@ -263,14 +338,14 @@ type FormInputElementProps = {
263
338
  * @property {ReactNode} children - The child elements, typically an input element.
264
339
  */
265
340
  type FormLabelElementProps = {
266
- name: string;
267
- title?: ReactNode;
268
- description?: ReactNode;
269
- error?: Error;
270
- /** as Input element */
271
- children: ReactNode;
341
+ name: string;
342
+ title?: ReactNode;
343
+ description?: ReactNode;
344
+ error?: Error; /** as Input element */
345
+ children: ReactNode;
272
346
  };
273
-
347
+ //#endregion
348
+ //#region src/Form/elements/index.d.ts
274
349
  /**
275
350
  * Represents the types of form elements used in the form.
276
351
  *
@@ -280,20 +355,22 @@ type FormLabelElementProps = {
280
355
  * @property {ComponentType<FormButtonElementProps>} Button - The component type for the form button element.
281
356
  */
282
357
  type FormElementTypes = {
283
- Label: ComponentType<FormLabelElementProps>;
284
- Input: ComponentType<FormInputElementProps>;
285
- Button: ComponentType<FormButtonElementProps>;
358
+ Label: ComponentType<FormLabelElementProps>;
359
+ Input: ComponentType<FormInputElementProps>;
360
+ Button: ComponentType<FormButtonElementProps>;
286
361
  };
287
362
  declare const FormDefaultElements: FormElementTypes;
288
-
363
+ //#endregion
364
+ //#region src/Form/lang.d.ts
289
365
  declare const FormDefaultLang: {
290
- submit: string;
291
- required: string;
292
- string: string;
293
- number: string;
366
+ submit: string;
367
+ required: string;
368
+ string: string;
369
+ number: string;
294
370
  };
295
371
  type FormLang = typeof FormDefaultLang;
296
-
372
+ //#endregion
373
+ //#region src/Form/rules.d.ts
297
374
  /**
298
375
  * A type representing a form validation rule.
299
376
  *
@@ -314,7 +391,7 @@ type FormLang = typeof FormDefaultLang;
314
391
  * ```
315
392
  */
316
393
  type FormRule<Options = any> = (value: any, options?: Options, lang?: FormLang) => Promise<void>;
317
- type InferRuleOption<T> = T extends (value: any, options: infer O, lang?: FormLang) => Promise<void> ? O : never;
394
+ type InferRuleOption<T> = T extends ((value: any, options: infer O, lang?: FormLang) => Promise<void>) ? O : never;
318
395
  /**
319
396
  * A type representing a set of form validation rules.
320
397
  *
@@ -323,46 +400,55 @@ type InferRuleOption<T> = T extends (value: any, options: infer O, lang?: FormLa
323
400
  * Each key in the record represents the name of a form field, and the corresponding value is a `FormRule` object that defines the validation rules for that field.
324
401
  */
325
402
  type FormRules = Record<string, FormRule>;
326
- type InferFormRulesOptions<T> = {
327
- [K in keyof T]: InferRuleOption<T[K]>;
328
- };
403
+ type InferFormRulesOptions<T> = { [K in keyof T]: InferRuleOption<T[K]> };
329
404
  /**
330
405
  * Default validation rules for a form.
331
- *
332
- * @constant
333
- * @type {FormRules}
334
406
  */
335
407
  declare const FormDefaultRules: FormRules;
336
408
  type FormDefaultRulesOptions = InferFormRulesOptions<typeof FormDefaultRules>;
337
409
  declare function validValues(rules: FormRules, items: FormItemProps[], values: Record<string, any>, lang: FormLang): Promise<Record<string, Error>>;
338
-
410
+ //#endregion
411
+ //#region src/Form/Input.d.ts
339
412
  type InferFormInputProps<T extends ComponentType<FormInputElementProps> | JSXElementConstructor<any>> = T extends ComponentType<FormInputElementProps> ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
340
413
  type FormInputProps<FormElements extends FormElementTypes = FormElementTypes> = {
341
- Input?: ComponentType<FormInputElementProps>;
342
- props?: InferFormInputProps<FormElements['Input']>;
414
+ Input?: ComponentType<FormInputElementProps>;
415
+ props?: InferFormInputProps<FormElements['Input']>;
343
416
  };
344
-
417
+ declare function FormInput({
418
+ name,
419
+ rules,
420
+ ...rest
421
+ }: FormInputProps & {
422
+ name: string;
423
+ rules?: FormDefaultRulesOptions;
424
+ }): react_jsx_runtime0.JSX.Element;
425
+ declare namespace FormInput {
426
+ var displayName: string;
427
+ }
428
+ //#endregion
429
+ //#region src/Form/Item.d.ts
345
430
  type FormItemName = string;
346
431
  type FormItemProps<FormElements extends FormElementTypes = FormElementTypes, FormRulesOptions extends Record<string, any> = FormDefaultRulesOptions> = {
347
- name: FormItemName;
348
- label?: Omit<FormLabelElementProps, 'name' | 'children'> & {
349
- Label?: ComponentType<FormLabelElementProps>;
350
- };
351
- input?: FormInputProps<FormElements>;
352
- rules?: FormRulesOptions;
432
+ name: FormItemName;
433
+ label?: Omit<FormLabelElementProps, 'name' | 'children'> & {
434
+ Label?: ComponentType<FormLabelElementProps>;
435
+ };
436
+ input?: FormInputProps<FormElements>;
437
+ rules?: FormRulesOptions;
353
438
  };
354
- declare function FormItem(props: FormItemProps): react_jsx_runtime.JSX.Element;
439
+ declare function FormItem(props: FormItemProps): react_jsx_runtime0.JSX.Element;
355
440
  declare namespace FormItem {
356
- var displayName: string;
441
+ var displayName: string;
357
442
  }
358
-
443
+ //#endregion
444
+ //#region src/Form/Container.d.ts
359
445
  type FormProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
360
- items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
361
- onSubmit?: (values: Values) => Promise<void>;
362
- Elements?: Partial<FormElements>;
363
- lang?: Partial<FormLang>;
364
- defaultValues?: Values;
365
- rules?: typeof FormDefaultRules & Rules;
446
+ items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
447
+ onSubmit?: (values: Values) => Promise<void>;
448
+ Elements?: Partial<FormElements>;
449
+ lang?: Partial<FormLang>;
450
+ defaultValues?: Values;
451
+ rules?: typeof FormDefaultRules & Rules;
366
452
  };
367
453
  /**
368
454
  * FormContainer component is a wrapper that provides context and state management for form elements.
@@ -394,40 +480,49 @@ type FormProps<Values extends Record<string, any> = Record<string, any>, FormEle
394
480
  * }
395
481
  * ```
396
482
  */
397
- declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules>({ defaultValues, Elements, rules, lang, items, ...props }: FormProps<Values, FormElements, Rules>): react_jsx_runtime.JSX.Element;
483
+ declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules>({
484
+ defaultValues,
485
+ Elements,
486
+ rules,
487
+ lang,
488
+ items,
489
+ ...props
490
+ }: FormProps<Values, FormElements, Rules>): react_jsx_runtime0.JSX.Element;
398
491
  declare namespace FormContainer {
399
- var displayName: string;
492
+ var displayName: string;
400
493
  }
401
-
494
+ //#endregion
495
+ //#region src/Form/context.d.ts
402
496
  type FormContextProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
403
- items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
404
- onSubmit: (values: Values) => Promise<void>;
405
- Elements: FormElementTypes;
406
- lang: FormLang;
407
- rules: typeof FormDefaultRules & Rules;
408
- submitting: boolean;
409
- setSubmitting: Dispatch<SetStateAction<boolean>>;
410
- values: Values;
411
- setValues: Dispatch<SetStateAction<Values>>;
412
- errors: Record<string, Error>;
413
- setErrors: Dispatch<SetStateAction<Record<string, Error>>>;
414
- valuesRef: RefObject<Values>;
497
+ items: FormItemProps<FormElements, InferFormRulesOptions<Rules>>[];
498
+ onSubmit: (values: Values) => Promise<void>;
499
+ Elements: FormElementTypes;
500
+ lang: FormLang;
501
+ rules: typeof FormDefaultRules & Rules;
502
+ submitting: boolean;
503
+ setSubmitting: Dispatch<SetStateAction<boolean>>;
504
+ values: Values;
505
+ setValues: Dispatch<SetStateAction<Values>>;
506
+ errors: Record<string, Error>;
507
+ setErrors: Dispatch<SetStateAction<Record<string, Error>>>;
508
+ valuesRef: RefObject<Values>;
415
509
  };
416
510
  declare const FormContextProvider: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>(props: {
417
- value?: Partial<NewT>;
418
- children: react.ReactNode;
419
- memo?: true | any[];
420
- initializeStates?: Partial<NewT>;
511
+ value?: Partial<NewT>;
512
+ children: react.ReactNode;
513
+ memo?: true | any[];
514
+ initializeStates?: Partial<NewT>;
421
515
  }) => react.ReactNode;
422
516
  declare const useFormContext: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>() => Readonly<NewT>;
423
-
517
+ //#endregion
518
+ //#region src/OptionalWrapper.d.ts
424
519
  type OptionalWrapperProps<TWrapper extends ComponentType<{
425
- children: ReactNode;
520
+ children: ReactNode;
426
521
  }> = any> = {
427
- condition: boolean;
428
- Wrapper: TWrapper;
429
- wrapperProps?: ComponentProps<TWrapper>;
430
- children: ReactNode;
522
+ condition: boolean;
523
+ Wrapper: TWrapper;
524
+ wrapperProps?: ComponentProps<TWrapper>;
525
+ children: ReactNode;
431
526
  };
432
527
  /**
433
528
  * A wrapper component that conditionally wraps its children with a provided wrapper component.
@@ -447,11 +542,17 @@ type OptionalWrapperProps<TWrapper extends ComponentType<{
447
542
  * )
448
543
  * ```
449
544
  */
450
- declare function OptionalWrapper({ condition, Wrapper, wrapperProps, children, }: OptionalWrapperProps): string | number | bigint | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode>>;
545
+ declare function OptionalWrapper({
546
+ condition,
547
+ Wrapper,
548
+ wrapperProps,
549
+ children
550
+ }: OptionalWrapperProps): string | number | bigint | boolean | react_jsx_runtime0.JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
451
551
  declare namespace OptionalWrapper {
452
- var displayName: string;
552
+ var displayName: string;
453
553
  }
454
-
554
+ //#endregion
555
+ //#region src/splittingContext.d.ts
455
556
  /**
456
557
  * Creates a splitting context with the given default value.
457
558
  *
@@ -495,76 +596,72 @@ declare namespace OptionalWrapper {
495
596
  * }
496
597
  * ```
497
598
  */
498
- declare function createSplittingContext<T extends Record<string, any>>(defaultValue: {
499
- [K in keyof T]: Partial<T[K]> | null;
500
- } | (keyof T)[]): {
599
+ declare function createSplittingContext<T extends Record<string, any>>(defaultValue: { [K in keyof T]: Partial<T[K]> | null } | (keyof T)[]): {
600
+ /**
601
+ * The provider component of the splitting context.
602
+ *
603
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
604
+ *
605
+ * @example
606
+ * ```tsx
607
+ * function App() {
608
+ * const [value, setValue] = useState(0)
609
+ *
610
+ * return (
611
+ * <Provider value={{ value, setValue }}>
612
+ * <ReaderComponent />
613
+ * <WriterComponent />
614
+ * </Provider>
615
+ * )
616
+ * }
617
+ * ```
618
+ */
619
+ Provider<NewT extends T = T>(props: {
620
+ value?: Partial<NewT>;
621
+ children: ReactNode;
501
622
  /**
502
- * The provider component of the splitting context.
503
- *
504
- * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
623
+ * Whether to use memoization for the children.
505
624
  *
506
- * @example
507
- * ```tsx
508
- * function App() {
509
- * const [value, setValue] = useState(0)
625
+ * @default false
510
626
  *
511
- * return (
512
- * <Provider value={{ value, setValue }}>
513
- * <ReaderComponent />
514
- * <WriterComponent />
515
- * </Provider>
516
- * )
517
- * }
518
- * ```
627
+ * `true`: memoize the children without dependencies.
628
+ * `any[]`: memoize the children with specific dependencies.
519
629
  */
520
- Provider<NewT extends T = T>(props: {
521
- value?: Partial<NewT>;
522
- children: ReactNode;
523
- /**
524
- * Whether to use memoization for the children.
525
- *
526
- * @default false
527
- *
528
- * `true`: memoize the children without dependencies.
529
- * `any[]`: memoize the children with specific dependencies.
530
- */
531
- memo?: true | any[];
532
- /**
533
- * An object containing initial values that will be automatically converted into state variables using {@link useSplittingState} hook. Each property will create both a state value and its setter following the pattern: value/setValue.
534
- *
535
- * @example
536
- * ```tsx
537
- * <Provider
538
- * initializeStates={{
539
- * value: 0,
540
- * }}
541
- * >
542
- * // Children will have access to: value, setValue
543
- * </Provider>
544
- */
545
- initializeStates?: Partial<NewT>;
546
- }): ReactNode;
630
+ memo?: true | any[];
547
631
  /**
548
- * The hook to use the splitting context.
549
- *
550
- * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#use
632
+ * An object containing initial values that will be automatically converted into state variables using {@link useSplittingState} hook. Each property will create both a state value and its setter following the pattern: value/setValue.
551
633
  *
552
634
  * @example
553
635
  * ```tsx
554
- * function ChildComponent() {
555
- * const { value, setValue } = use()
556
- *
557
- * return <div>{value}<button onClick={() => setValue(1)}>change value</button></div>
558
- * }
559
- * ```
636
+ * <Provider
637
+ * initializeStates={{
638
+ * value: 0,
639
+ * }}
640
+ * >
641
+ * // Children will have access to: value, setValue
642
+ * </Provider>
560
643
  */
561
- use: <NewT extends T = T>() => Readonly<NewT>;
562
- };
563
-
564
- type SetPrefix<S extends string | number | symbol> = S extends string ? S extends `${infer First}${infer Rest}` ? `set${Capitalize<First>}${Rest}` : never : never;
565
- type StateSetters<T> = {
566
- [K in keyof T as SetPrefix<K>]: Dispatch<SetStateAction<T[K]>>;
644
+ initializeStates?: Partial<NewT>;
645
+ }): ReactNode;
646
+ /**
647
+ * The hook to use the splitting context.
648
+ *
649
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#use
650
+ *
651
+ * @example
652
+ * ```tsx
653
+ * function ChildComponent() {
654
+ * const { value, setValue } = use()
655
+ *
656
+ * return <div>{value}<button onClick={() => setValue(1)}>change value</button></div>
657
+ * }
658
+ * ```
659
+ */
660
+ use: <NewT extends T = T>() => Readonly<NewT>;
567
661
  };
662
+ //#endregion
663
+ //#region src/splittingState.d.ts
664
+ type StateSetters<T> = { [K in keyof T as K extends string ? K extends `${infer First}${infer Rest}` ? `set${Capitalize<First>}${Rest}` : never : never]: Dispatch<SetStateAction<T[K]>> };
568
665
  type StatesWithSetters<T> = T & StateSetters<T>;
569
666
  /**
570
667
  * A hook that initializes and splits state variables and their corresponding setters.
@@ -582,32 +679,32 @@ type StatesWithSetters<T> = T & StateSetters<T>;
582
679
  * ```
583
680
  */
584
681
  declare function useSplittingState<T extends Record<string, unknown>>(initialStates: T): StatesWithSetters<T>;
585
-
682
+ //#endregion
683
+ //#region src/useFaasStream.d.ts
586
684
  type UseFaasStreamOptions = {
587
- params?: Record<string, any>;
588
- data?: string;
589
- setData?: React.Dispatch<React.SetStateAction<string>>;
590
- /**
591
- * If skip is true, the request will not be sent.
592
- *
593
- * However, you can still use reload to send the request.
594
- */
595
- skip?: boolean | ((params: Record<string, any>) => boolean);
596
- /** Send the last request after milliseconds */
597
- debounce?: number;
598
- baseUrl?: BaseUrl;
685
+ params?: Record<string, any>;
686
+ data?: string;
687
+ setData?: React.Dispatch<React.SetStateAction<string>>;
688
+ /**
689
+ * If skip is true, the request will not be sent.
690
+ *
691
+ * However, you can still use reload to send the request.
692
+ */
693
+ skip?: boolean | ((params: Record<string, any>) => boolean); /** Send the last request after milliseconds */
694
+ debounce?: number;
695
+ baseUrl?: BaseUrl;
599
696
  };
600
697
  type UseFaasStreamResult = {
601
- action: string;
602
- params: Record<string, any>;
603
- loading: boolean;
604
- reloadTimes: number;
605
- data: string;
606
- error: any;
607
- reload: (params?: Record<string, any>) => Promise<string>;
608
- setData: React.Dispatch<React.SetStateAction<string>>;
609
- setLoading: React.Dispatch<React.SetStateAction<boolean>>;
610
- setError: React.Dispatch<React.SetStateAction<any>>;
698
+ action: string;
699
+ params: Record<string, any>;
700
+ loading: boolean;
701
+ reloadTimes: number;
702
+ data: string;
703
+ error: any;
704
+ reload: (params?: Record<string, any>) => Promise<string>;
705
+ setData: React.Dispatch<React.SetStateAction<string>>;
706
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
707
+ setError: React.Dispatch<React.SetStateAction<any>>;
611
708
  };
612
709
  /**
613
710
  * Stream faas server response with React hook
@@ -633,7 +730,8 @@ type UseFaasStreamResult = {
633
730
  * ```
634
731
  */
635
732
  declare function useFaasStream(action: string, defaultParams: Record<string, any>, options?: UseFaasStreamOptions): UseFaasStreamResult;
636
-
733
+ //#endregion
734
+ //#region src/usePrevious.d.ts
637
735
  /**
638
736
  * Hook to store the previous value of a state or prop.
639
737
  *
@@ -642,7 +740,8 @@ declare function useFaasStream(action: string, defaultParams: Record<string, any
642
740
  * @returns {T | undefined} - The previous value, or undefined if there is no previous value.
643
741
  */
644
742
  declare function usePrevious<T = any>(value: T): T | undefined;
645
-
743
+ //#endregion
744
+ //#region src/useStateRef.d.ts
646
745
  /**
647
746
  * Custom hook that returns a stateful value and a ref to that value.
648
747
  *
@@ -665,6 +764,6 @@ declare function usePrevious<T = any>(value: T): T | undefined;
665
764
  * </div>
666
765
  * )
667
766
  */
668
- declare function useStateRef<T = any>(initialValue?: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>];
669
-
670
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, type FaasDataWrapperRef, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, FormContainer as Form, type FormButtonElementProps, type FormContextProps, FormContextProvider, FormDefaultElements, FormDefaultLang, FormDefaultRules, type FormDefaultRulesOptions, type FormElementTypes, type FormInputElementProps, FormItem, type FormItemName, type FormItemProps, type FormLabelElementProps, type FormLang, type FormProps, type FormRule, type FormRules, type InferFormRulesOptions, type OnError, OptionalWrapper, type OptionalWrapperProps, type UseFaasStreamOptions, type UseFaasStreamResult, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, type useFaasOptions, useFaasStream, useFormContext, usePrevious, useSplittingState, useStateRef, validValues, withFaasData };
767
+ declare function useStateRef<T = any>(initialValue?: T): [T | null, Dispatch<SetStateAction<T | null>>, RefObject<T | null>];
768
+ //#endregion
769
+ export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, type FaasAction, type FaasActionUnionType, type FaasData, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasDataWrapperRef, type FaasParams, FaasReactClient, FaasReactClientInstance, FaasReactClientOptions, FormContainer as Form, type FormButtonElementProps, FormContextProps, FormContextProvider, FormDefaultElements, FormDefaultLang, FormDefaultRules, FormDefaultRulesOptions, FormElementTypes, FormInput, type FormInputElementProps, FormInputProps, FormItem, FormItemName, FormItemProps, type FormLabelElementProps, FormLang, type FormProps, FormRule, FormRules, InferFormInputProps, InferFormRulesOptions, InferRuleOption, OnError, OptionalWrapper, OptionalWrapperProps, type Options, type Response, type ResponseError, type ResponseHeaders, StateSetters, StatesWithSetters, UseFaasStreamOptions, UseFaasStreamResult, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFaasOptions, useFaasStream, useFormContext, usePrevious, useSplittingState, useStateRef, validValues, withFaasData };