@faasjs/react 8.0.0-beta.6 → 8.0.0-beta.8
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.cjs +938 -674
- package/dist/index.d.ts +356 -258
- package/dist/index.mjs +937 -672
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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,29 +169,29 @@ 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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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.
|
|
@@ -136,7 +205,11 @@ type FaasReactClientInstance = {
|
|
|
136
205
|
* })
|
|
137
206
|
* ```
|
|
138
207
|
*/
|
|
139
|
-
declare function FaasReactClient({
|
|
208
|
+
declare function FaasReactClient({
|
|
209
|
+
baseUrl,
|
|
210
|
+
options: clientOptions,
|
|
211
|
+
onError
|
|
212
|
+
}?: FaasReactClientOptions): FaasReactClientInstance;
|
|
140
213
|
/**
|
|
141
214
|
* Get FaasReactClient instance
|
|
142
215
|
*
|
|
@@ -151,35 +224,36 @@ declare function FaasReactClient({ baseUrl, options, onError }?: FaasReactClient
|
|
|
151
224
|
* ```
|
|
152
225
|
*/
|
|
153
226
|
declare function getClient(host?: string): FaasReactClientInstance;
|
|
154
|
-
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/constant.d.ts
|
|
155
229
|
/**
|
|
156
230
|
* Returns a constant value that is created by the given function.
|
|
157
231
|
*/
|
|
158
232
|
declare function useConstant<T>(fn: () => T): T;
|
|
159
|
-
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/ErrorBoundary.d.ts
|
|
160
235
|
interface ErrorBoundaryProps {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
236
|
+
children?: ReactNode;
|
|
237
|
+
onError?: (error: Error | null, info: any) => void;
|
|
238
|
+
errorChildren?: ReactElement<ErrorChildrenProps>;
|
|
164
239
|
}
|
|
165
240
|
type ErrorChildrenProps = {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
241
|
+
error?: Error;
|
|
242
|
+
info?: any;
|
|
243
|
+
errorMessage?: string;
|
|
244
|
+
errorDescription?: string;
|
|
170
245
|
};
|
|
171
246
|
declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
componentStack?: string;
|
|
175
|
-
};
|
|
247
|
+
error: Error | null;
|
|
248
|
+
info: ErrorInfo;
|
|
176
249
|
}> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
250
|
+
static displayName: string;
|
|
251
|
+
constructor(props: ErrorBoundaryProps);
|
|
252
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
253
|
+
render(): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime0.JSX.Element | null;
|
|
181
254
|
}
|
|
182
|
-
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/equal.d.ts
|
|
183
257
|
/**
|
|
184
258
|
* Compares two values for deep equality.
|
|
185
259
|
*
|
|
@@ -223,7 +297,8 @@ declare function useEqualMemo<T>(callback: () => T, dependencies: any[]): T;
|
|
|
223
297
|
* @returns The result of the `useCallback` hook with memoized dependencies.
|
|
224
298
|
*/
|
|
225
299
|
declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T, dependencies: any[]): T;
|
|
226
|
-
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/Form/elements/Button.d.ts
|
|
227
302
|
/**
|
|
228
303
|
* Props for the FormButtonElement component.
|
|
229
304
|
*
|
|
@@ -232,11 +307,12 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
|
|
|
232
307
|
* @property {() => Promise<void>} submit - A function to be called when the button is clicked, which returns a promise.
|
|
233
308
|
*/
|
|
234
309
|
type FormButtonElementProps = {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
310
|
+
children?: React.ReactNode;
|
|
311
|
+
submitting: boolean;
|
|
312
|
+
submit: () => Promise<void>;
|
|
238
313
|
};
|
|
239
|
-
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/Form/elements/Input.d.ts
|
|
240
316
|
/**
|
|
241
317
|
* Props for the Form Input Element component.
|
|
242
318
|
*
|
|
@@ -245,11 +321,12 @@ type FormButtonElementProps = {
|
|
|
245
321
|
* @property {(value: any) => void} onChange - Callback function to handle changes to the input value.
|
|
246
322
|
*/
|
|
247
323
|
type FormInputElementProps = {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
324
|
+
name: string;
|
|
325
|
+
value: any;
|
|
326
|
+
onChange: (value: any) => void;
|
|
251
327
|
};
|
|
252
|
-
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/Form/elements/Label.d.ts
|
|
253
330
|
/**
|
|
254
331
|
* Props for the FormLabelElement component.
|
|
255
332
|
*
|
|
@@ -261,14 +338,14 @@ type FormInputElementProps = {
|
|
|
261
338
|
* @property {ReactNode} children - The child elements, typically an input element.
|
|
262
339
|
*/
|
|
263
340
|
type FormLabelElementProps = {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
children: ReactNode;
|
|
341
|
+
name: string;
|
|
342
|
+
title?: ReactNode;
|
|
343
|
+
description?: ReactNode;
|
|
344
|
+
error?: Error; /** as Input element */
|
|
345
|
+
children: ReactNode;
|
|
270
346
|
};
|
|
271
|
-
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/Form/elements/index.d.ts
|
|
272
349
|
/**
|
|
273
350
|
* Represents the types of form elements used in the form.
|
|
274
351
|
*
|
|
@@ -278,20 +355,22 @@ type FormLabelElementProps = {
|
|
|
278
355
|
* @property {ComponentType<FormButtonElementProps>} Button - The component type for the form button element.
|
|
279
356
|
*/
|
|
280
357
|
type FormElementTypes = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
358
|
+
Label: ComponentType<FormLabelElementProps>;
|
|
359
|
+
Input: ComponentType<FormInputElementProps>;
|
|
360
|
+
Button: ComponentType<FormButtonElementProps>;
|
|
284
361
|
};
|
|
285
362
|
declare const FormDefaultElements: FormElementTypes;
|
|
286
|
-
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/Form/lang.d.ts
|
|
287
365
|
declare const FormDefaultLang: {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
366
|
+
submit: string;
|
|
367
|
+
required: string;
|
|
368
|
+
string: string;
|
|
369
|
+
number: string;
|
|
292
370
|
};
|
|
293
371
|
type FormLang = typeof FormDefaultLang;
|
|
294
|
-
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/Form/rules.d.ts
|
|
295
374
|
/**
|
|
296
375
|
* A type representing a form validation rule.
|
|
297
376
|
*
|
|
@@ -312,7 +391,7 @@ type FormLang = typeof FormDefaultLang;
|
|
|
312
391
|
* ```
|
|
313
392
|
*/
|
|
314
393
|
type FormRule<Options = any> = (value: any, options?: Options, lang?: FormLang) => Promise<void>;
|
|
315
|
-
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;
|
|
316
395
|
/**
|
|
317
396
|
* A type representing a set of form validation rules.
|
|
318
397
|
*
|
|
@@ -321,50 +400,55 @@ type InferRuleOption<T> = T extends (value: any, options: infer O, lang?: FormLa
|
|
|
321
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.
|
|
322
401
|
*/
|
|
323
402
|
type FormRules = Record<string, FormRule>;
|
|
324
|
-
type InferFormRulesOptions<T> = {
|
|
325
|
-
[K in keyof T]: InferRuleOption<T[K]>;
|
|
326
|
-
};
|
|
403
|
+
type InferFormRulesOptions<T> = { [K in keyof T]: InferRuleOption<T[K]> };
|
|
327
404
|
/**
|
|
328
405
|
* Default validation rules for a form.
|
|
329
406
|
*/
|
|
330
407
|
declare const FormDefaultRules: FormRules;
|
|
331
408
|
type FormDefaultRulesOptions = InferFormRulesOptions<typeof FormDefaultRules>;
|
|
332
409
|
declare function validValues(rules: FormRules, items: FormItemProps[], values: Record<string, any>, lang: FormLang): Promise<Record<string, Error>>;
|
|
333
|
-
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region src/Form/Input.d.ts
|
|
334
412
|
type InferFormInputProps<T extends ComponentType<FormInputElementProps> | JSXElementConstructor<any>> = T extends ComponentType<FormInputElementProps> ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
|
|
335
413
|
type FormInputProps<FormElements extends FormElementTypes = FormElementTypes> = {
|
|
336
|
-
|
|
337
|
-
|
|
414
|
+
Input?: ComponentType<FormInputElementProps>;
|
|
415
|
+
props?: InferFormInputProps<FormElements['Input']>;
|
|
338
416
|
};
|
|
339
|
-
declare function FormInput({
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
417
|
+
declare function FormInput({
|
|
418
|
+
name,
|
|
419
|
+
rules,
|
|
420
|
+
...rest
|
|
421
|
+
}: FormInputProps & {
|
|
422
|
+
name: string;
|
|
423
|
+
rules?: FormDefaultRulesOptions;
|
|
424
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
343
425
|
declare namespace FormInput {
|
|
344
|
-
|
|
426
|
+
var displayName: string;
|
|
345
427
|
}
|
|
346
|
-
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/Form/Item.d.ts
|
|
347
430
|
type FormItemName = string;
|
|
348
431
|
type FormItemProps<FormElements extends FormElementTypes = FormElementTypes, FormRulesOptions extends Record<string, any> = FormDefaultRulesOptions> = {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
432
|
+
name: FormItemName;
|
|
433
|
+
label?: Omit<FormLabelElementProps, 'name' | 'children'> & {
|
|
434
|
+
Label?: ComponentType<FormLabelElementProps>;
|
|
435
|
+
};
|
|
436
|
+
input?: FormInputProps<FormElements>;
|
|
437
|
+
rules?: FormRulesOptions;
|
|
355
438
|
};
|
|
356
|
-
declare function FormItem(props: FormItemProps):
|
|
439
|
+
declare function FormItem(props: FormItemProps): react_jsx_runtime0.JSX.Element;
|
|
357
440
|
declare namespace FormItem {
|
|
358
|
-
|
|
441
|
+
var displayName: string;
|
|
359
442
|
}
|
|
360
|
-
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/Form/Container.d.ts
|
|
361
445
|
type FormProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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;
|
|
368
452
|
};
|
|
369
453
|
/**
|
|
370
454
|
* FormContainer component is a wrapper that provides context and state management for form elements.
|
|
@@ -396,40 +480,49 @@ type FormProps<Values extends Record<string, any> = Record<string, any>, FormEle
|
|
|
396
480
|
* }
|
|
397
481
|
* ```
|
|
398
482
|
*/
|
|
399
|
-
declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules>({
|
|
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;
|
|
400
491
|
declare namespace FormContainer {
|
|
401
|
-
|
|
492
|
+
var displayName: string;
|
|
402
493
|
}
|
|
403
|
-
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/Form/context.d.ts
|
|
404
496
|
type FormContextProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes, Rules extends FormRules = typeof FormDefaultRules> = {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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>;
|
|
417
509
|
};
|
|
418
510
|
declare const FormContextProvider: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>(props: {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
511
|
+
value?: Partial<NewT>;
|
|
512
|
+
children: react.ReactNode;
|
|
513
|
+
memo?: true | any[];
|
|
514
|
+
initializeStates?: Partial<NewT>;
|
|
423
515
|
}) => react.ReactNode;
|
|
424
516
|
declare const useFormContext: <NewT extends FormContextProps<Record<string, any>, FormElementTypes, FormRules> = FormContextProps<Record<string, any>, FormElementTypes, FormRules>>() => Readonly<NewT>;
|
|
425
|
-
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/OptionalWrapper.d.ts
|
|
426
519
|
type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
427
|
-
|
|
520
|
+
children: ReactNode;
|
|
428
521
|
}> = any> = {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
522
|
+
condition: boolean;
|
|
523
|
+
Wrapper: TWrapper;
|
|
524
|
+
wrapperProps?: ComponentProps<TWrapper>;
|
|
525
|
+
children: ReactNode;
|
|
433
526
|
};
|
|
434
527
|
/**
|
|
435
528
|
* A wrapper component that conditionally wraps its children with a provided wrapper component.
|
|
@@ -449,11 +542,17 @@ type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
|
449
542
|
* )
|
|
450
543
|
* ```
|
|
451
544
|
*/
|
|
452
|
-
declare function OptionalWrapper({
|
|
545
|
+
declare function OptionalWrapper({
|
|
546
|
+
condition,
|
|
547
|
+
Wrapper,
|
|
548
|
+
wrapperProps,
|
|
549
|
+
children
|
|
550
|
+
}: OptionalWrapperProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | react_jsx_runtime0.JSX.Element | null | undefined;
|
|
453
551
|
declare namespace OptionalWrapper {
|
|
454
|
-
|
|
552
|
+
var displayName: string;
|
|
455
553
|
}
|
|
456
|
-
|
|
554
|
+
//#endregion
|
|
555
|
+
//#region src/splittingContext.d.ts
|
|
457
556
|
/**
|
|
458
557
|
* Creates a splitting context with the given default value.
|
|
459
558
|
*
|
|
@@ -497,75 +596,72 @@ declare namespace OptionalWrapper {
|
|
|
497
596
|
* }
|
|
498
597
|
* ```
|
|
499
598
|
*/
|
|
500
|
-
declare function createSplittingContext<T extends Record<string, any>>(defaultValue: {
|
|
501
|
-
|
|
502
|
-
|
|
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;
|
|
503
622
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
|
|
623
|
+
* Whether to use memoization for the children.
|
|
507
624
|
*
|
|
508
|
-
* @
|
|
509
|
-
* ```tsx
|
|
510
|
-
* function App() {
|
|
511
|
-
* const [value, setValue] = useState(0)
|
|
625
|
+
* @default false
|
|
512
626
|
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
* <ReaderComponent />
|
|
516
|
-
* <WriterComponent />
|
|
517
|
-
* </Provider>
|
|
518
|
-
* )
|
|
519
|
-
* }
|
|
520
|
-
* ```
|
|
627
|
+
* `true`: memoize the children without dependencies.
|
|
628
|
+
* `any[]`: memoize the children with specific dependencies.
|
|
521
629
|
*/
|
|
522
|
-
|
|
523
|
-
value?: Partial<NewT>;
|
|
524
|
-
children: ReactNode;
|
|
525
|
-
/**
|
|
526
|
-
* Whether to use memoization for the children.
|
|
527
|
-
*
|
|
528
|
-
* @default false
|
|
529
|
-
*
|
|
530
|
-
* `true`: memoize the children without dependencies.
|
|
531
|
-
* `any[]`: memoize the children with specific dependencies.
|
|
532
|
-
*/
|
|
533
|
-
memo?: true | any[];
|
|
534
|
-
/**
|
|
535
|
-
* 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.
|
|
536
|
-
*
|
|
537
|
-
* @example
|
|
538
|
-
* ```tsx
|
|
539
|
-
* <Provider
|
|
540
|
-
* initializeStates={{
|
|
541
|
-
* value: 0,
|
|
542
|
-
* }}
|
|
543
|
-
* >
|
|
544
|
-
* // Children will have access to: value, setValue
|
|
545
|
-
* </Provider>
|
|
546
|
-
*/
|
|
547
|
-
initializeStates?: Partial<NewT>;
|
|
548
|
-
}): ReactNode;
|
|
630
|
+
memo?: true | any[];
|
|
549
631
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
* @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.
|
|
553
633
|
*
|
|
554
634
|
* @example
|
|
555
635
|
* ```tsx
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
636
|
+
* <Provider
|
|
637
|
+
* initializeStates={{
|
|
638
|
+
* value: 0,
|
|
639
|
+
* }}
|
|
640
|
+
* >
|
|
641
|
+
* // Children will have access to: value, setValue
|
|
642
|
+
* </Provider>
|
|
562
643
|
*/
|
|
563
|
-
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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>;
|
|
568
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]>> };
|
|
569
665
|
type StatesWithSetters<T> = T & StateSetters<T>;
|
|
570
666
|
/**
|
|
571
667
|
* A hook that initializes and splits state variables and their corresponding setters.
|
|
@@ -583,32 +679,32 @@ type StatesWithSetters<T> = T & StateSetters<T>;
|
|
|
583
679
|
* ```
|
|
584
680
|
*/
|
|
585
681
|
declare function useSplittingState<T extends Record<string, unknown>>(initialStates: T): StatesWithSetters<T>;
|
|
586
|
-
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/useFaasStream.d.ts
|
|
587
684
|
type UseFaasStreamOptions = {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
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;
|
|
600
696
|
};
|
|
601
697
|
type UseFaasStreamResult = {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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>>;
|
|
612
708
|
};
|
|
613
709
|
/**
|
|
614
710
|
* Stream faas server response with React hook
|
|
@@ -634,7 +730,8 @@ type UseFaasStreamResult = {
|
|
|
634
730
|
* ```
|
|
635
731
|
*/
|
|
636
732
|
declare function useFaasStream(action: string, defaultParams: Record<string, any>, options?: UseFaasStreamOptions): UseFaasStreamResult;
|
|
637
|
-
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region src/usePrevious.d.ts
|
|
638
735
|
/**
|
|
639
736
|
* Hook to store the previous value of a state or prop.
|
|
640
737
|
*
|
|
@@ -643,7 +740,8 @@ declare function useFaasStream(action: string, defaultParams: Record<string, any
|
|
|
643
740
|
* @returns {T | undefined} - The previous value, or undefined if there is no previous value.
|
|
644
741
|
*/
|
|
645
742
|
declare function usePrevious<T = any>(value: T): T | undefined;
|
|
646
|
-
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/useStateRef.d.ts
|
|
647
745
|
/**
|
|
648
746
|
* Custom hook that returns a stateful value and a ref to that value.
|
|
649
747
|
*
|
|
@@ -666,6 +764,6 @@ declare function usePrevious<T = any>(value: T): T | undefined;
|
|
|
666
764
|
* </div>
|
|
667
765
|
* )
|
|
668
766
|
*/
|
|
669
|
-
declare function useStateRef<T = any>(initialValue?: T): [T, Dispatch<SetStateAction<T>>, RefObject<T>];
|
|
670
|
-
|
|
671
|
-
export { ErrorBoundary, type
|
|
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 };
|