@faasjs/react 3.7.0-beta.0 → 3.7.0-beta.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/README.md CHANGED
@@ -45,6 +45,7 @@ npm install @faasjs/react
45
45
  - [FaasDataWrapper](functions/FaasDataWrapper.md)
46
46
  - [FaasReactClient](functions/FaasReactClient.md)
47
47
  - [Form](functions/Form.md)
48
+ - [FormContextProvider](functions/FormContextProvider.md)
48
49
  - [getClient](functions/getClient.md)
49
50
  - [OptionalWrapper](functions/OptionalWrapper.md)
50
51
  - [useConstant](functions/useConstant.md)
@@ -53,6 +54,7 @@ npm install @faasjs/react
53
54
  - [useEqualMemo](functions/useEqualMemo.md)
54
55
  - [useEqualMemoize](functions/useEqualMemoize.md)
55
56
  - [useFaas](functions/useFaas.md)
57
+ - [useFormContext](functions/useFormContext.md)
56
58
  - [useSplittingState](functions/useSplittingState.md)
57
59
  - [withFaasData](functions/withFaasData.md)
58
60
 
@@ -76,8 +78,18 @@ npm install @faasjs/react
76
78
  - [FaasParams](type-aliases/FaasParams.md)
77
79
  - [FaasReactClientInstance](type-aliases/FaasReactClientInstance.md)
78
80
  - [FaasReactClientOptions](type-aliases/FaasReactClientOptions.md)
81
+ - [FormButtonElementProps](type-aliases/FormButtonElementProps.md)
82
+ - [FormContextProps](type-aliases/FormContextProps.md)
83
+ - [FormElementTypes](type-aliases/FormElementTypes.md)
84
+ - [FormInputElementProps](type-aliases/FormInputElementProps.md)
85
+ - [FormLabelElementProps](type-aliases/FormLabelElementProps.md)
86
+ - [FormProps](type-aliases/FormProps.md)
79
87
  - [OnError](type-aliases/OnError.md)
80
88
  - [OptionalWrapperProps](type-aliases/OptionalWrapperProps.md)
81
89
  - [Options](type-aliases/Options.md)
82
90
  - [ResponseHeaders](type-aliases/ResponseHeaders.md)
83
91
  - [useFaasOptions](type-aliases/useFaasOptions.md)
92
+
93
+ ## Variables
94
+
95
+ - [FormDefaultElements](variables/FormDefaultElements.md)
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
2
2
  export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Response, BaseUrl, ResponseError, Options, FaasBrowserClient } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
+ import * as react from 'react';
5
6
  import { ReactNode, Dispatch, SetStateAction, ReactElement, Component, ComponentType, ComponentProps, JSXElementConstructor } from 'react';
6
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
@@ -211,6 +212,7 @@ type FaasDataWrapperProps<PathOrData extends FaasAction> = {
211
212
  };
212
213
  declare function FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
213
214
  declare namespace FaasDataWrapper {
215
+ var displayName: string;
214
216
  var whyDidYouRender: boolean;
215
217
  }
216
218
  /**
@@ -335,6 +337,7 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
335
337
  componentStack?: string;
336
338
  };
337
339
  }> {
340
+ static displayName: string;
338
341
  static whyDidYouRender: boolean;
339
342
  constructor(props: ErrorBoundaryProps);
340
343
  componentDidCatch(error: Error | null, info: any): void;
@@ -376,59 +379,66 @@ type FormRules = {
376
379
  required?: boolean;
377
380
  };
378
381
 
379
- type FormInputComponentProps = {
382
+ type FormInputElementProps = {
380
383
  name: string;
381
384
  value: any;
382
385
  onChange: (value: any) => void;
383
386
  };
384
- type FormInputComponent<Extra extends Record<string, any> = Record<string, any>> = ComponentType<FormInputComponentProps & Extra>;
385
- type InferFormInputProps<T extends FormInputComponent | JSXElementConstructor<any>> = T extends FormInputComponent ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
387
+
388
+ type InferFormInputProps<T extends ComponentType<FormInputElementProps> | JSXElementConstructor<any>> = T extends ComponentType<FormInputElementProps> ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
386
389
  type FormInputProps<FormElements extends FormElementTypes = FormElementTypes> = {
387
- Input: FormInputComponent;
388
- } | {
389
- type?: 'input';
390
- props?: InferFormInputProps<FormElements['input']>;
391
- } | {
392
- type: 'select';
393
- props?: InferFormInputProps<FormElements['select']>;
390
+ Input?: ComponentType<FormInputElementProps>;
391
+ props?: InferFormInputProps<FormElements['Input']>;
394
392
  };
395
393
 
396
- type FormLabelProps<FormElements extends FormElementTypes = FormElementTypes> = {
394
+ type FormLabelElementProps<FormElements extends FormElementTypes = FormElementTypes> = {
397
395
  name: string;
398
396
  rules?: FormRules;
399
- label?: {
400
- title?: ReactNode;
401
- description?: ReactNode;
402
- Label?: React.ComponentType<FormLabelProps>;
403
- };
397
+ title?: ReactNode;
398
+ description?: ReactNode;
399
+ Label?: FormElements['Label'];
404
400
  input?: FormInputProps<FormElements>;
405
401
  };
406
402
 
407
- type FormButtonProps = {
403
+ type FormButtonElementProps = {
408
404
  children?: React.ReactNode;
409
405
  disabled?: boolean;
410
406
  onClick?: () => void;
411
407
  };
412
408
 
413
- type FormSelectOption = {
414
- value: string | number;
415
- label: string;
416
- };
417
409
  type FormElementTypes = {
418
- label: ComponentType<FormLabelProps>;
419
- input: FormInputComponent;
420
- select: FormInputComponent<{
421
- options?: FormSelectOption[];
422
- }>;
423
- button: ComponentType<FormButtonProps>;
410
+ Label: ComponentType<FormLabelElementProps>;
411
+ Input: ComponentType<FormInputElementProps>;
412
+ Button: ComponentType<FormButtonElementProps>;
424
413
  };
414
+ declare const FormDefaultElements: FormElementTypes;
425
415
 
426
416
  type FormProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes> = {
427
- items: FormLabelProps<FormElements>[];
417
+ items: FormLabelElementProps[];
428
418
  onSubmit?: (values: Values) => Promise<void>;
429
- elements?: FormElements;
419
+ elements?: Partial<FormElements>;
430
420
  defaultValues?: Values;
431
421
  };
432
422
  declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes>({ defaultValues, elements, ...props }: FormProps<Values, FormElements>): react_jsx_runtime.JSX.Element;
423
+ declare namespace FormContainer {
424
+ var displayName: string;
425
+ var whyDidYouRender: boolean;
426
+ }
427
+
428
+ type FormContextProps<Values extends Record<string, any> = Record<string, any>> = {
429
+ items: FormLabelElementProps[];
430
+ onSubmit: (values: Values) => Promise<void>;
431
+ Elements: FormElementTypes;
432
+ submitting: boolean;
433
+ setSubmitting: React.Dispatch<React.SetStateAction<boolean>>;
434
+ values: Values;
435
+ setValues: React.Dispatch<React.SetStateAction<Values>>;
436
+ };
437
+ declare const FormContextProvider: <NewT extends FormContextProps<Record<string, any>> = FormContextProps<Record<string, any>>>(props: {
438
+ value?: NewT;
439
+ children: react.ReactNode;
440
+ memo?: true | any[];
441
+ }) => react.ReactNode;
442
+ declare const useFormContext: <NewT extends FormContextProps<Record<string, any>> = FormContextProps<Record<string, any>>>() => Readonly<NewT>;
433
443
 
434
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, FormContainer as Form, type OnError, OptionalWrapper, type OptionalWrapperProps, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, type useFaasOptions, useSplittingState, withFaasData };
444
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, FormContainer as Form, type FormButtonElementProps, type FormContextProps, FormContextProvider, FormDefaultElements, type FormElementTypes, type FormInputElementProps, type FormLabelElementProps, type FormProps, type OnError, OptionalWrapper, type OptionalWrapperProps, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, type useFaasOptions, useFormContext, useSplittingState, withFaasData };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
2
2
  export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Response, BaseUrl, ResponseError, Options, FaasBrowserClient } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
+ import * as react from 'react';
5
6
  import { ReactNode, Dispatch, SetStateAction, ReactElement, Component, ComponentType, ComponentProps, JSXElementConstructor } from 'react';
6
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
@@ -211,6 +212,7 @@ type FaasDataWrapperProps<PathOrData extends FaasAction> = {
211
212
  };
212
213
  declare function FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
213
214
  declare namespace FaasDataWrapper {
215
+ var displayName: string;
214
216
  var whyDidYouRender: boolean;
215
217
  }
216
218
  /**
@@ -335,6 +337,7 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
335
337
  componentStack?: string;
336
338
  };
337
339
  }> {
340
+ static displayName: string;
338
341
  static whyDidYouRender: boolean;
339
342
  constructor(props: ErrorBoundaryProps);
340
343
  componentDidCatch(error: Error | null, info: any): void;
@@ -376,59 +379,66 @@ type FormRules = {
376
379
  required?: boolean;
377
380
  };
378
381
 
379
- type FormInputComponentProps = {
382
+ type FormInputElementProps = {
380
383
  name: string;
381
384
  value: any;
382
385
  onChange: (value: any) => void;
383
386
  };
384
- type FormInputComponent<Extra extends Record<string, any> = Record<string, any>> = ComponentType<FormInputComponentProps & Extra>;
385
- type InferFormInputProps<T extends FormInputComponent | JSXElementConstructor<any>> = T extends FormInputComponent ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
387
+
388
+ type InferFormInputProps<T extends ComponentType<FormInputElementProps> | JSXElementConstructor<any>> = T extends ComponentType<FormInputElementProps> ? Omit<ComponentProps<T>, 'name' | 'value' | 'onChange'> : Omit<ComponentProps<T>, 'name' | 'value'>;
386
389
  type FormInputProps<FormElements extends FormElementTypes = FormElementTypes> = {
387
- Input: FormInputComponent;
388
- } | {
389
- type?: 'input';
390
- props?: InferFormInputProps<FormElements['input']>;
391
- } | {
392
- type: 'select';
393
- props?: InferFormInputProps<FormElements['select']>;
390
+ Input?: ComponentType<FormInputElementProps>;
391
+ props?: InferFormInputProps<FormElements['Input']>;
394
392
  };
395
393
 
396
- type FormLabelProps<FormElements extends FormElementTypes = FormElementTypes> = {
394
+ type FormLabelElementProps<FormElements extends FormElementTypes = FormElementTypes> = {
397
395
  name: string;
398
396
  rules?: FormRules;
399
- label?: {
400
- title?: ReactNode;
401
- description?: ReactNode;
402
- Label?: React.ComponentType<FormLabelProps>;
403
- };
397
+ title?: ReactNode;
398
+ description?: ReactNode;
399
+ Label?: FormElements['Label'];
404
400
  input?: FormInputProps<FormElements>;
405
401
  };
406
402
 
407
- type FormButtonProps = {
403
+ type FormButtonElementProps = {
408
404
  children?: React.ReactNode;
409
405
  disabled?: boolean;
410
406
  onClick?: () => void;
411
407
  };
412
408
 
413
- type FormSelectOption = {
414
- value: string | number;
415
- label: string;
416
- };
417
409
  type FormElementTypes = {
418
- label: ComponentType<FormLabelProps>;
419
- input: FormInputComponent;
420
- select: FormInputComponent<{
421
- options?: FormSelectOption[];
422
- }>;
423
- button: ComponentType<FormButtonProps>;
410
+ Label: ComponentType<FormLabelElementProps>;
411
+ Input: ComponentType<FormInputElementProps>;
412
+ Button: ComponentType<FormButtonElementProps>;
424
413
  };
414
+ declare const FormDefaultElements: FormElementTypes;
425
415
 
426
416
  type FormProps<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes> = {
427
- items: FormLabelProps<FormElements>[];
417
+ items: FormLabelElementProps[];
428
418
  onSubmit?: (values: Values) => Promise<void>;
429
- elements?: FormElements;
419
+ elements?: Partial<FormElements>;
430
420
  defaultValues?: Values;
431
421
  };
432
422
  declare function FormContainer<Values extends Record<string, any> = Record<string, any>, FormElements extends FormElementTypes = FormElementTypes>({ defaultValues, elements, ...props }: FormProps<Values, FormElements>): react_jsx_runtime.JSX.Element;
423
+ declare namespace FormContainer {
424
+ var displayName: string;
425
+ var whyDidYouRender: boolean;
426
+ }
427
+
428
+ type FormContextProps<Values extends Record<string, any> = Record<string, any>> = {
429
+ items: FormLabelElementProps[];
430
+ onSubmit: (values: Values) => Promise<void>;
431
+ Elements: FormElementTypes;
432
+ submitting: boolean;
433
+ setSubmitting: React.Dispatch<React.SetStateAction<boolean>>;
434
+ values: Values;
435
+ setValues: React.Dispatch<React.SetStateAction<Values>>;
436
+ };
437
+ declare const FormContextProvider: <NewT extends FormContextProps<Record<string, any>> = FormContextProps<Record<string, any>>>(props: {
438
+ value?: NewT;
439
+ children: react.ReactNode;
440
+ memo?: true | any[];
441
+ }) => react.ReactNode;
442
+ declare const useFormContext: <NewT extends FormContextProps<Record<string, any>> = FormContextProps<Record<string, any>>>() => Readonly<NewT>;
433
443
 
434
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, FormContainer as Form, type OnError, OptionalWrapper, type OptionalWrapperProps, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, type useFaasOptions, useSplittingState, withFaasData };
444
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, FormContainer as Form, type FormButtonElementProps, type FormContextProps, FormContextProvider, FormDefaultElements, type FormElementTypes, type FormInputElementProps, type FormLabelElementProps, type FormProps, type OnError, OptionalWrapper, type OptionalWrapperProps, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, type useFaasOptions, useFormContext, useSplittingState, withFaasData };
package/dist/index.js CHANGED
@@ -4,7 +4,37 @@ var react = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var browser = require('@faasjs/browser');
6
6
 
7
- // src/constant.ts
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols)
32
+ for (var prop of __getOwnPropSymbols(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
8
38
  function useConstant(fn) {
9
39
  const ref = react.useRef();
10
40
  if (!ref.current) {
@@ -88,17 +118,20 @@ function createSplittingContext(defaultValue) {
88
118
  const contexts = {};
89
119
  for (const key of keys) contexts[key] = react.createContext(defaultValues[key]);
90
120
  function Provider(props) {
121
+ var _a, _b;
91
122
  let children = props.memo ? useEqualMemo(
92
123
  () => props.children,
93
124
  props.memo === true ? [] : props.memo
94
125
  ) : props.children;
95
126
  for (const key of keys) {
96
127
  const Context = contexts[key];
97
- const value = props.value?.[key] ?? defaultValues[key];
128
+ const value = (_b = (_a = props.value) == null ? void 0 : _a[key]) != null ? _b : defaultValues[key];
98
129
  children = /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value, children });
99
130
  }
100
131
  return children;
101
132
  }
133
+ Provider.displayName = "SplittingContextProvider";
134
+ Provider.whyDidYouRender = true;
102
135
  function use() {
103
136
  return useConstant(() => {
104
137
  const obj = /* @__PURE__ */ Object.create(null);
@@ -110,6 +143,7 @@ function createSplittingContext(defaultValue) {
110
143
  return Object.freeze(obj);
111
144
  });
112
145
  }
146
+ use.whyDidYouRender = true;
113
147
  return {
114
148
  Provider,
115
149
  use
@@ -155,9 +189,10 @@ function FaasDataWrapper(props) {
155
189
  ]);
156
190
  return child;
157
191
  }
192
+ FaasDataWrapper.displayName = "FaasDataWrapper";
158
193
  FaasDataWrapper.whyDidYouRender = true;
159
194
  function withFaasData(Component2, faasProps) {
160
- return (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { ...props }) });
195
+ return (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, __spreadProps(__spreadValues({}, faasProps), { children: /* @__PURE__ */ jsxRuntime.jsx(Component2, __spreadValues({}, props)) }));
161
196
  }
162
197
  function useFaas(action, defaultParams, options = {}) {
163
198
  const [loading, setLoading] = react.useState(true);
@@ -200,9 +235,9 @@ function useFaas(action, defaultParams, options = {}) {
200
235
  options.setData ? options.setData(r.data) : setData(r.data);
201
236
  setLoading(false);
202
237
  }).catch(async (e) => {
203
- if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
238
+ if (typeof (e == null ? void 0 : e.message) === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
204
239
  return;
205
- if (!fails && typeof e?.message === "string" && e.message.indexOf("Failed to fetch") >= 0) {
240
+ if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
206
241
  console.warn(`FaasReactClient: ${e.message} retry...`);
207
242
  setFails(1);
208
243
  return send();
@@ -221,14 +256,16 @@ function useFaas(action, defaultParams, options = {}) {
221
256
  if (options.debounce) {
222
257
  const timeout = setTimeout(send, options.debounce);
223
258
  return () => {
259
+ var _a;
224
260
  clearTimeout(timeout);
225
- controllerRef.current?.abort();
261
+ (_a = controllerRef.current) == null ? void 0 : _a.abort();
226
262
  setLoading(false);
227
263
  };
228
264
  }
229
265
  send();
230
266
  return () => {
231
- controllerRef.current?.abort();
267
+ var _a;
268
+ (_a = controllerRef.current) == null ? void 0 : _a.abort();
232
269
  setLoading(false);
233
270
  };
234
271
  }, [action, options.params || params, reloadTimes, skip]);
@@ -260,7 +297,7 @@ useFaas.whyDidYouRender = true;
260
297
 
261
298
  // src/faas.ts
262
299
  async function faas(action, params, options) {
263
- const client = getClient(options?.baseUrl);
300
+ const client = getClient(options == null ? void 0 : options.baseUrl);
264
301
  if (client.onError)
265
302
  return client.browserClient.action(action, params, options).catch(async (res) => {
266
303
  await client.onError(action, params)(res);
@@ -275,9 +312,9 @@ function FaasReactClient({ baseUrl, options, onError } = {
275
312
  const client = new browser.FaasBrowserClient(baseUrl, options);
276
313
  const reactClient = {
277
314
  id: client.id,
278
- faas: async (action, params, options2) => faas(action, params, { baseUrl, ...options2 }),
279
- useFaas: (action, defaultParams, options2) => useFaas(action, defaultParams, { baseUrl, ...options2 }),
280
- FaasDataWrapper: (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { baseUrl, ...props }),
315
+ faas: async (action, params, options2) => faas(action, params, __spreadValues({ baseUrl }, options2)),
316
+ useFaas: (action, defaultParams, options2) => useFaas(action, defaultParams, __spreadValues({ baseUrl }, options2)),
317
+ FaasDataWrapper: (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, __spreadValues({ baseUrl }, props)),
281
318
  onError,
282
319
  browserClient: client
283
320
  };
@@ -293,7 +330,6 @@ function getClient(host) {
293
330
  return client;
294
331
  }
295
332
  var ErrorBoundary = class extends react.Component {
296
- static whyDidYouRender = true;
297
333
  constructor(props) {
298
334
  super(props);
299
335
  this.state = {
@@ -308,8 +344,9 @@ var ErrorBoundary = class extends react.Component {
308
344
  });
309
345
  }
310
346
  render() {
347
+ var _a;
311
348
  const errorMessage = (this.state.error || "").toString();
312
- const errorDescription = this.state.info?.componentStack ? this.state.info.componentStack : null;
349
+ const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
313
350
  if (this.state.error) {
314
351
  if (this.props.onError)
315
352
  this.props.onError(this.state.error, this.state.info);
@@ -328,117 +365,108 @@ var ErrorBoundary = class extends react.Component {
328
365
  return this.props.children;
329
366
  }
330
367
  };
368
+ ErrorBoundary.displayName = "ErrorBoundary";
331
369
  ErrorBoundary.whyDidYouRender = true;
332
370
  var OptionalWrapper = ({ condition, Wrapper, wrapperProps, children }) => {
333
- return condition ? /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...wrapperProps, children }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
371
+ return condition ? /* @__PURE__ */ jsxRuntime.jsx(Wrapper, __spreadProps(__spreadValues({}, wrapperProps), { children })) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
334
372
  };
373
+ OptionalWrapper.displayName = "OptionalWrapper";
335
374
  OptionalWrapper.whyDidYouRender = true;
336
375
 
337
376
  // src/Form/context.tsx
338
- var FormContext = createSplittingContext(["items", "onSubmit", "elements", "submitting", "setSubmitting", "values", "setValues"]);
377
+ var FormContext = createSplittingContext(["items", "onSubmit", "Elements", "submitting", "setSubmitting", "values", "setValues"]);
339
378
  var FormContextProvider = FormContext.Provider;
340
379
  var useFormContext = FormContext.use;
341
380
  function FormLabel(props) {
342
- const { elements } = useFormContext();
343
- if (props.label?.Label) return /* @__PURE__ */ jsxRuntime.jsx(props.label.Label, { ...props });
344
- return /* @__PURE__ */ jsxRuntime.jsx(elements.label, { ...props });
381
+ const { Elements } = useFormContext();
382
+ if (props.Label) return /* @__PURE__ */ jsxRuntime.jsx(props.Label, __spreadValues({}, props));
383
+ return /* @__PURE__ */ jsxRuntime.jsx(Elements.Label, __spreadValues({}, props));
345
384
  }
385
+ FormLabel.displayName = "FormLabel";
386
+ FormLabel.whyDidYouRender = true;
346
387
  function FormBody() {
347
388
  const { items } = useFormContext();
348
- return items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { ...item }, item.name));
349
- }
350
- function processValue(input, rules) {
351
- let value = input;
352
- if (typeof input === "object" && "target" in input) {
353
- value = input.target.value;
354
- }
355
- switch (rules?.type) {
356
- case "number":
357
- return Number(value);
358
- case "string":
359
- return String(value);
360
- default:
361
- return value;
362
- }
389
+ return items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(FormLabel, __spreadValues({}, item), item.name));
363
390
  }
364
- function FormInput({
391
+ FormBody.displayName = "FormBody";
392
+ FormBody.whyDidYouRender = true;
393
+ var FormInputElement = react.forwardRef((_a, ref) => {
394
+ var _b = _a, { onChange } = _b, props = __objRest(_b, ["onChange"]);
395
+ return /* @__PURE__ */ jsxRuntime.jsx("input", __spreadProps(__spreadValues({}, props), { onChange: (e) => onChange(e.target.value), ref }));
396
+ });
397
+ FormInputElement.displayName = "FormInputElement";
398
+ FormInputElement.whyDidYouRender = true;
399
+ var FormLabelElement = ({
365
400
  name,
366
- rules,
367
- ...rest
368
- }) {
369
- const { elements, values, setValues } = useFormContext();
370
- const value = values?.[name];
371
- if ("Input" in rest && rest.Input) {
401
+ title,
402
+ description,
403
+ Label,
404
+ input
405
+ }) => {
406
+ const { values, setValues } = useFormContext();
407
+ if (Label)
372
408
  return /* @__PURE__ */ jsxRuntime.jsx(
373
- rest.Input,
409
+ Label,
374
410
  {
375
411
  name,
376
- value,
377
- onChange: (v) => setValues((prev) => ({
378
- ...prev,
412
+ title,
413
+ description,
414
+ input
415
+ }
416
+ );
417
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
418
+ title != null ? title : name,
419
+ (input == null ? void 0 : input.Input) ? /* @__PURE__ */ jsxRuntime.jsx(
420
+ input.Input,
421
+ {
422
+ name,
423
+ value: values[name],
424
+ onChange: (v) => setValues((prev) => __spreadProps(__spreadValues({}, prev), {
379
425
  [name]: v
380
426
  }))
381
427
  }
382
- );
383
- }
384
- if ("type" in rest || "props" in rest) {
385
- switch (rest.type) {
386
- case "select":
387
- return /* @__PURE__ */ jsxRuntime.jsx(
388
- elements.select,
389
- {
390
- name,
391
- value,
392
- onChange: (v) => setValues((prev) => ({
393
- ...prev,
394
- [name]: processValue(v, rules)
395
- })),
396
- ...rest.props
397
- }
398
- );
399
- default:
400
- return /* @__PURE__ */ jsxRuntime.jsx(
401
- elements.input,
402
- {
403
- name,
404
- value,
405
- onChange: (v) => setValues((prev) => ({
406
- ...prev,
407
- [name]: processValue(v, rules)
408
- })),
409
- ...rest.props
410
- }
411
- );
412
- }
413
- }
428
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
429
+ FormInputElement,
430
+ {
431
+ name,
432
+ value: values[name],
433
+ onChange: (v) => setValues((prev) => __spreadProps(__spreadValues({}, prev), {
434
+ [name]: v
435
+ }))
436
+ }
437
+ ),
438
+ description
439
+ ] });
440
+ };
441
+ FormLabelElement.displayName = "FormLabelElement";
442
+ FormLabelElement.whyDidYouRender = true;
443
+ var FormButtonElement = react.forwardRef((_a, ref) => {
444
+ var _b = _a, { disabled, children, onClick } = _b, props = __objRest(_b, ["disabled", "children", "onClick"]);
414
445
  return /* @__PURE__ */ jsxRuntime.jsx(
415
- elements.input,
416
- {
417
- name,
418
- value,
419
- onChange: (v) => setValues((prev) => ({
420
- ...prev,
421
- [name]: processValue(v, rules)
422
- }))
423
- }
446
+ "button",
447
+ __spreadProps(__spreadValues({
448
+ type: "button",
449
+ disabled,
450
+ onClick
451
+ }, props), {
452
+ ref,
453
+ children
454
+ })
424
455
  );
425
- }
426
- var FormElements = {
427
- label: react.forwardRef(({ name, label, input, rules }, ref) => /* @__PURE__ */ jsxRuntime.jsxs("label", { ref, children: [
428
- label?.title ?? name,
429
- /* @__PURE__ */ jsxRuntime.jsx(FormInput, { name, rules, ...input }),
430
- label?.description
431
- ] })),
432
- input: react.forwardRef(
433
- (props, ref) => /* @__PURE__ */ jsxRuntime.jsx("input", { ...props, ref })
434
- ),
435
- select: react.forwardRef(({ options, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("select", { ...props, ref, children: options?.map((option) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value)) })),
436
- button: react.forwardRef(({ disabled, children, onClick, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", disabled, onClick, ...props, ref, children }))
456
+ });
457
+ FormButtonElement.displayName = "FormButtonElement";
458
+ FormButtonElement.whyDidYouRender = true;
459
+
460
+ // src/Form/elements/index.ts
461
+ var FormDefaultElements = {
462
+ Label: FormLabelElement,
463
+ Input: FormInputElement,
464
+ Button: FormButtonElement
437
465
  };
438
466
  function FormFooter() {
439
- const { submitting, setSubmitting, onSubmit, values, elements } = useFormContext();
467
+ const { submitting, setSubmitting, onSubmit, values, Elements } = useFormContext();
440
468
  return /* @__PURE__ */ jsxRuntime.jsx(
441
- elements.button,
469
+ Elements.Button,
442
470
  {
443
471
  disabled: submitting,
444
472
  onClick: () => {
@@ -449,25 +477,26 @@ function FormFooter() {
449
477
  }
450
478
  );
451
479
  }
480
+ FormFooter.displayName = "FormFooter";
481
+ FormFooter.whyDidYouRender = true;
452
482
  function mergeValues(items, defaultValues = {}) {
483
+ var _a;
453
484
  const values = {};
454
485
  for (const item of items)
455
- values[item.name] = defaultValues[item.name] ?? "";
486
+ values[item.name] = (_a = defaultValues[item.name]) != null ? _a : "";
456
487
  return values;
457
488
  }
458
- function FormContainer({ defaultValues, elements, ...props }) {
489
+ function FormContainer(_a) {
490
+ var _b = _a, { defaultValues, elements } = _b, props = __objRest(_b, ["defaultValues", "elements"]);
459
491
  const states = useSplittingState({
460
492
  values: mergeValues(props.items, defaultValues),
461
493
  submitting: false,
462
- elements: Object.assign(FormElements, elements)
494
+ Elements: Object.assign(FormDefaultElements, elements)
463
495
  });
464
496
  return /* @__PURE__ */ jsxRuntime.jsxs(
465
497
  FormContextProvider,
466
498
  {
467
- value: {
468
- ...states,
469
- ...props
470
- },
499
+ value: __spreadValues(__spreadValues({}, states), props),
471
500
  children: [
472
501
  /* @__PURE__ */ jsxRuntime.jsx(FormBody, {}),
473
502
  /* @__PURE__ */ jsxRuntime.jsx(FormFooter, {})
@@ -475,11 +504,15 @@ function FormContainer({ defaultValues, elements, ...props }) {
475
504
  }
476
505
  );
477
506
  }
507
+ FormContainer.displayName = "FormContainer";
508
+ FormContainer.whyDidYouRender = true;
478
509
 
479
510
  exports.ErrorBoundary = ErrorBoundary;
480
511
  exports.FaasDataWrapper = FaasDataWrapper;
481
512
  exports.FaasReactClient = FaasReactClient;
482
513
  exports.Form = FormContainer;
514
+ exports.FormContextProvider = FormContextProvider;
515
+ exports.FormDefaultElements = FormDefaultElements;
483
516
  exports.OptionalWrapper = OptionalWrapper;
484
517
  exports.createSplittingContext = createSplittingContext;
485
518
  exports.equal = equal;
@@ -491,5 +524,6 @@ exports.useEqualEffect = useEqualEffect;
491
524
  exports.useEqualMemo = useEqualMemo;
492
525
  exports.useEqualMemoize = useEqualMemoize;
493
526
  exports.useFaas = useFaas;
527
+ exports.useFormContext = useFormContext;
494
528
  exports.useSplittingState = useSplittingState;
495
529
  exports.withFaasData = withFaasData;
package/dist/index.mjs CHANGED
@@ -1,8 +1,38 @@
1
1
  import { forwardRef, useRef, useMemo, useEffect, useCallback, createContext, useState, cloneElement, Component, useContext } from 'react';
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { FaasBrowserClient } from '@faasjs/browser';
4
4
 
5
- // src/constant.ts
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
6
36
  function useConstant(fn) {
7
37
  const ref = useRef();
8
38
  if (!ref.current) {
@@ -86,17 +116,20 @@ function createSplittingContext(defaultValue) {
86
116
  const contexts = {};
87
117
  for (const key of keys) contexts[key] = createContext(defaultValues[key]);
88
118
  function Provider(props) {
119
+ var _a, _b;
89
120
  let children = props.memo ? useEqualMemo(
90
121
  () => props.children,
91
122
  props.memo === true ? [] : props.memo
92
123
  ) : props.children;
93
124
  for (const key of keys) {
94
125
  const Context = contexts[key];
95
- const value = props.value?.[key] ?? defaultValues[key];
126
+ const value = (_b = (_a = props.value) == null ? void 0 : _a[key]) != null ? _b : defaultValues[key];
96
127
  children = /* @__PURE__ */ jsx(Context.Provider, { value, children });
97
128
  }
98
129
  return children;
99
130
  }
131
+ Provider.displayName = "SplittingContextProvider";
132
+ Provider.whyDidYouRender = true;
100
133
  function use() {
101
134
  return useConstant(() => {
102
135
  const obj = /* @__PURE__ */ Object.create(null);
@@ -108,6 +141,7 @@ function createSplittingContext(defaultValue) {
108
141
  return Object.freeze(obj);
109
142
  });
110
143
  }
144
+ use.whyDidYouRender = true;
111
145
  return {
112
146
  Provider,
113
147
  use
@@ -153,9 +187,10 @@ function FaasDataWrapper(props) {
153
187
  ]);
154
188
  return child;
155
189
  }
190
+ FaasDataWrapper.displayName = "FaasDataWrapper";
156
191
  FaasDataWrapper.whyDidYouRender = true;
157
192
  function withFaasData(Component2, faasProps) {
158
- return (props) => /* @__PURE__ */ jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsx(Component2, { ...props }) });
193
+ return (props) => /* @__PURE__ */ jsx(FaasDataWrapper, __spreadProps(__spreadValues({}, faasProps), { children: /* @__PURE__ */ jsx(Component2, __spreadValues({}, props)) }));
159
194
  }
160
195
  function useFaas(action, defaultParams, options = {}) {
161
196
  const [loading, setLoading] = useState(true);
@@ -198,9 +233,9 @@ function useFaas(action, defaultParams, options = {}) {
198
233
  options.setData ? options.setData(r.data) : setData(r.data);
199
234
  setLoading(false);
200
235
  }).catch(async (e) => {
201
- if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
236
+ if (typeof (e == null ? void 0 : e.message) === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
202
237
  return;
203
- if (!fails && typeof e?.message === "string" && e.message.indexOf("Failed to fetch") >= 0) {
238
+ if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
204
239
  console.warn(`FaasReactClient: ${e.message} retry...`);
205
240
  setFails(1);
206
241
  return send();
@@ -219,14 +254,16 @@ function useFaas(action, defaultParams, options = {}) {
219
254
  if (options.debounce) {
220
255
  const timeout = setTimeout(send, options.debounce);
221
256
  return () => {
257
+ var _a;
222
258
  clearTimeout(timeout);
223
- controllerRef.current?.abort();
259
+ (_a = controllerRef.current) == null ? void 0 : _a.abort();
224
260
  setLoading(false);
225
261
  };
226
262
  }
227
263
  send();
228
264
  return () => {
229
- controllerRef.current?.abort();
265
+ var _a;
266
+ (_a = controllerRef.current) == null ? void 0 : _a.abort();
230
267
  setLoading(false);
231
268
  };
232
269
  }, [action, options.params || params, reloadTimes, skip]);
@@ -258,7 +295,7 @@ useFaas.whyDidYouRender = true;
258
295
 
259
296
  // src/faas.ts
260
297
  async function faas(action, params, options) {
261
- const client = getClient(options?.baseUrl);
298
+ const client = getClient(options == null ? void 0 : options.baseUrl);
262
299
  if (client.onError)
263
300
  return client.browserClient.action(action, params, options).catch(async (res) => {
264
301
  await client.onError(action, params)(res);
@@ -273,9 +310,9 @@ function FaasReactClient({ baseUrl, options, onError } = {
273
310
  const client = new FaasBrowserClient(baseUrl, options);
274
311
  const reactClient = {
275
312
  id: client.id,
276
- faas: async (action, params, options2) => faas(action, params, { baseUrl, ...options2 }),
277
- useFaas: (action, defaultParams, options2) => useFaas(action, defaultParams, { baseUrl, ...options2 }),
278
- FaasDataWrapper: (props) => /* @__PURE__ */ jsx(FaasDataWrapper, { baseUrl, ...props }),
313
+ faas: async (action, params, options2) => faas(action, params, __spreadValues({ baseUrl }, options2)),
314
+ useFaas: (action, defaultParams, options2) => useFaas(action, defaultParams, __spreadValues({ baseUrl }, options2)),
315
+ FaasDataWrapper: (props) => /* @__PURE__ */ jsx(FaasDataWrapper, __spreadValues({ baseUrl }, props)),
279
316
  onError,
280
317
  browserClient: client
281
318
  };
@@ -291,7 +328,6 @@ function getClient(host) {
291
328
  return client;
292
329
  }
293
330
  var ErrorBoundary = class extends Component {
294
- static whyDidYouRender = true;
295
331
  constructor(props) {
296
332
  super(props);
297
333
  this.state = {
@@ -306,8 +342,9 @@ var ErrorBoundary = class extends Component {
306
342
  });
307
343
  }
308
344
  render() {
345
+ var _a;
309
346
  const errorMessage = (this.state.error || "").toString();
310
- const errorDescription = this.state.info?.componentStack ? this.state.info.componentStack : null;
347
+ const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
311
348
  if (this.state.error) {
312
349
  if (this.props.onError)
313
350
  this.props.onError(this.state.error, this.state.info);
@@ -326,117 +363,108 @@ var ErrorBoundary = class extends Component {
326
363
  return this.props.children;
327
364
  }
328
365
  };
366
+ ErrorBoundary.displayName = "ErrorBoundary";
329
367
  ErrorBoundary.whyDidYouRender = true;
330
368
  var OptionalWrapper = ({ condition, Wrapper, wrapperProps, children }) => {
331
- return condition ? /* @__PURE__ */ jsx(Wrapper, { ...wrapperProps, children }) : /* @__PURE__ */ jsx(Fragment, { children });
369
+ return condition ? /* @__PURE__ */ jsx(Wrapper, __spreadProps(__spreadValues({}, wrapperProps), { children })) : /* @__PURE__ */ jsx(Fragment, { children });
332
370
  };
371
+ OptionalWrapper.displayName = "OptionalWrapper";
333
372
  OptionalWrapper.whyDidYouRender = true;
334
373
 
335
374
  // src/Form/context.tsx
336
- var FormContext = createSplittingContext(["items", "onSubmit", "elements", "submitting", "setSubmitting", "values", "setValues"]);
375
+ var FormContext = createSplittingContext(["items", "onSubmit", "Elements", "submitting", "setSubmitting", "values", "setValues"]);
337
376
  var FormContextProvider = FormContext.Provider;
338
377
  var useFormContext = FormContext.use;
339
378
  function FormLabel(props) {
340
- const { elements } = useFormContext();
341
- if (props.label?.Label) return /* @__PURE__ */ jsx(props.label.Label, { ...props });
342
- return /* @__PURE__ */ jsx(elements.label, { ...props });
379
+ const { Elements } = useFormContext();
380
+ if (props.Label) return /* @__PURE__ */ jsx(props.Label, __spreadValues({}, props));
381
+ return /* @__PURE__ */ jsx(Elements.Label, __spreadValues({}, props));
343
382
  }
383
+ FormLabel.displayName = "FormLabel";
384
+ FormLabel.whyDidYouRender = true;
344
385
  function FormBody() {
345
386
  const { items } = useFormContext();
346
- return items.map((item) => /* @__PURE__ */ jsx(FormLabel, { ...item }, item.name));
347
- }
348
- function processValue(input, rules) {
349
- let value = input;
350
- if (typeof input === "object" && "target" in input) {
351
- value = input.target.value;
352
- }
353
- switch (rules?.type) {
354
- case "number":
355
- return Number(value);
356
- case "string":
357
- return String(value);
358
- default:
359
- return value;
360
- }
387
+ return items.map((item) => /* @__PURE__ */ jsx(FormLabel, __spreadValues({}, item), item.name));
361
388
  }
362
- function FormInput({
389
+ FormBody.displayName = "FormBody";
390
+ FormBody.whyDidYouRender = true;
391
+ var FormInputElement = forwardRef((_a, ref) => {
392
+ var _b = _a, { onChange } = _b, props = __objRest(_b, ["onChange"]);
393
+ return /* @__PURE__ */ jsx("input", __spreadProps(__spreadValues({}, props), { onChange: (e) => onChange(e.target.value), ref }));
394
+ });
395
+ FormInputElement.displayName = "FormInputElement";
396
+ FormInputElement.whyDidYouRender = true;
397
+ var FormLabelElement = ({
363
398
  name,
364
- rules,
365
- ...rest
366
- }) {
367
- const { elements, values, setValues } = useFormContext();
368
- const value = values?.[name];
369
- if ("Input" in rest && rest.Input) {
399
+ title,
400
+ description,
401
+ Label,
402
+ input
403
+ }) => {
404
+ const { values, setValues } = useFormContext();
405
+ if (Label)
370
406
  return /* @__PURE__ */ jsx(
371
- rest.Input,
407
+ Label,
372
408
  {
373
409
  name,
374
- value,
375
- onChange: (v) => setValues((prev) => ({
376
- ...prev,
410
+ title,
411
+ description,
412
+ input
413
+ }
414
+ );
415
+ return /* @__PURE__ */ jsxs("label", { children: [
416
+ title != null ? title : name,
417
+ (input == null ? void 0 : input.Input) ? /* @__PURE__ */ jsx(
418
+ input.Input,
419
+ {
420
+ name,
421
+ value: values[name],
422
+ onChange: (v) => setValues((prev) => __spreadProps(__spreadValues({}, prev), {
377
423
  [name]: v
378
424
  }))
379
425
  }
380
- );
381
- }
382
- if ("type" in rest || "props" in rest) {
383
- switch (rest.type) {
384
- case "select":
385
- return /* @__PURE__ */ jsx(
386
- elements.select,
387
- {
388
- name,
389
- value,
390
- onChange: (v) => setValues((prev) => ({
391
- ...prev,
392
- [name]: processValue(v, rules)
393
- })),
394
- ...rest.props
395
- }
396
- );
397
- default:
398
- return /* @__PURE__ */ jsx(
399
- elements.input,
400
- {
401
- name,
402
- value,
403
- onChange: (v) => setValues((prev) => ({
404
- ...prev,
405
- [name]: processValue(v, rules)
406
- })),
407
- ...rest.props
408
- }
409
- );
410
- }
411
- }
426
+ ) : /* @__PURE__ */ jsx(
427
+ FormInputElement,
428
+ {
429
+ name,
430
+ value: values[name],
431
+ onChange: (v) => setValues((prev) => __spreadProps(__spreadValues({}, prev), {
432
+ [name]: v
433
+ }))
434
+ }
435
+ ),
436
+ description
437
+ ] });
438
+ };
439
+ FormLabelElement.displayName = "FormLabelElement";
440
+ FormLabelElement.whyDidYouRender = true;
441
+ var FormButtonElement = forwardRef((_a, ref) => {
442
+ var _b = _a, { disabled, children, onClick } = _b, props = __objRest(_b, ["disabled", "children", "onClick"]);
412
443
  return /* @__PURE__ */ jsx(
413
- elements.input,
414
- {
415
- name,
416
- value,
417
- onChange: (v) => setValues((prev) => ({
418
- ...prev,
419
- [name]: processValue(v, rules)
420
- }))
421
- }
444
+ "button",
445
+ __spreadProps(__spreadValues({
446
+ type: "button",
447
+ disabled,
448
+ onClick
449
+ }, props), {
450
+ ref,
451
+ children
452
+ })
422
453
  );
423
- }
424
- var FormElements = {
425
- label: forwardRef(({ name, label, input, rules }, ref) => /* @__PURE__ */ jsxs("label", { ref, children: [
426
- label?.title ?? name,
427
- /* @__PURE__ */ jsx(FormInput, { name, rules, ...input }),
428
- label?.description
429
- ] })),
430
- input: forwardRef(
431
- (props, ref) => /* @__PURE__ */ jsx("input", { ...props, ref })
432
- ),
433
- select: forwardRef(({ options, ...props }, ref) => /* @__PURE__ */ jsx("select", { ...props, ref, children: options?.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value)) })),
434
- button: forwardRef(({ disabled, children, onClick, ...props }, ref) => /* @__PURE__ */ jsx("button", { type: "button", disabled, onClick, ...props, ref, children }))
454
+ });
455
+ FormButtonElement.displayName = "FormButtonElement";
456
+ FormButtonElement.whyDidYouRender = true;
457
+
458
+ // src/Form/elements/index.ts
459
+ var FormDefaultElements = {
460
+ Label: FormLabelElement,
461
+ Input: FormInputElement,
462
+ Button: FormButtonElement
435
463
  };
436
464
  function FormFooter() {
437
- const { submitting, setSubmitting, onSubmit, values, elements } = useFormContext();
465
+ const { submitting, setSubmitting, onSubmit, values, Elements } = useFormContext();
438
466
  return /* @__PURE__ */ jsx(
439
- elements.button,
467
+ Elements.Button,
440
468
  {
441
469
  disabled: submitting,
442
470
  onClick: () => {
@@ -447,25 +475,26 @@ function FormFooter() {
447
475
  }
448
476
  );
449
477
  }
478
+ FormFooter.displayName = "FormFooter";
479
+ FormFooter.whyDidYouRender = true;
450
480
  function mergeValues(items, defaultValues = {}) {
481
+ var _a;
451
482
  const values = {};
452
483
  for (const item of items)
453
- values[item.name] = defaultValues[item.name] ?? "";
484
+ values[item.name] = (_a = defaultValues[item.name]) != null ? _a : "";
454
485
  return values;
455
486
  }
456
- function FormContainer({ defaultValues, elements, ...props }) {
487
+ function FormContainer(_a) {
488
+ var _b = _a, { defaultValues, elements } = _b, props = __objRest(_b, ["defaultValues", "elements"]);
457
489
  const states = useSplittingState({
458
490
  values: mergeValues(props.items, defaultValues),
459
491
  submitting: false,
460
- elements: Object.assign(FormElements, elements)
492
+ Elements: Object.assign(FormDefaultElements, elements)
461
493
  });
462
494
  return /* @__PURE__ */ jsxs(
463
495
  FormContextProvider,
464
496
  {
465
- value: {
466
- ...states,
467
- ...props
468
- },
497
+ value: __spreadValues(__spreadValues({}, states), props),
469
498
  children: [
470
499
  /* @__PURE__ */ jsx(FormBody, {}),
471
500
  /* @__PURE__ */ jsx(FormFooter, {})
@@ -473,5 +502,7 @@ function FormContainer({ defaultValues, elements, ...props }) {
473
502
  }
474
503
  );
475
504
  }
505
+ FormContainer.displayName = "FormContainer";
506
+ FormContainer.whyDidYouRender = true;
476
507
 
477
- export { ErrorBoundary, FaasDataWrapper, FaasReactClient, FormContainer as Form, OptionalWrapper, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useSplittingState, withFaasData };
508
+ export { ErrorBoundary, FaasDataWrapper, FaasReactClient, FormContainer as Form, FormContextProvider, FormDefaultElements, OptionalWrapper, createSplittingContext, equal, faas, getClient, useConstant, useEqualCallback, useEqualEffect, useEqualMemo, useEqualMemoize, useFaas, useFormContext, useSplittingState, withFaasData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "3.7.0-beta.0",
3
+ "version": "3.7.0-beta.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,10 +34,10 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@faasjs/browser": "3.7.0-beta.0"
37
+ "@faasjs/browser": "3.7.0-beta.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@faasjs/browser": "3.7.0-beta.0",
40
+ "@faasjs/browser": "3.7.0-beta.2",
41
41
  "@types/react": "*",
42
42
  "react": "*"
43
43
  },