react-form-action 2.18.0 → 2.19.1

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
@@ -67,9 +67,8 @@ export const subscribeAction = formAction
67
67
 
68
68
  import {
69
69
  Form,
70
- Pending,
70
+ Submit,
71
71
  createComponents,
72
- useActionContext,
73
72
  } from "react-form-action/client";
74
73
 
75
74
  import { subscribeAction } from "./action";
@@ -77,13 +76,12 @@ import { subscribeAction } from "./action";
77
76
  const { FieldError, Success } = createComponents(subscribeAction);
78
77
 
79
78
  export function SubscribeForm() {
80
- const { isPending, isFailure, error, data } =
81
- useActionContext(subscribeAction);
82
-
83
79
  return (
84
80
  <Form>
85
81
  <Success>
86
- <p>✅ Email {data} was registered.</p>
82
+ {({ isSuccess, data }) =>
83
+ isSuccess && <p>✅ Please check your email :{data}.</p>
84
+ }
87
85
  </Success>
88
86
  {/*💡 The FieldError "name" prop supports autocompletion */}
89
87
  <FieldError name="email">
@@ -91,10 +89,13 @@ export function SubscribeForm() {
91
89
  <input className={error ? "invalid" : ""} name={name} />
92
90
  )}
93
91
  </FieldError>
94
- <button type="submit" disabled={isPending}>
95
- {isPending ? "🌀 Submitting..." : "Submit"}
96
- </button>
97
- <Pending>Please wait...</Pending>
92
+ <Submit>
93
+ {({ pending, disabled }) => (
94
+ <button type="submit" disabled={disabled}>
95
+ {pending ? "🌀 Submitting..." : "Submit"}
96
+ </button>
97
+ )}
98
+ </Submit>
98
99
  </Form>
99
100
  );
100
101
  }
@@ -111,7 +112,7 @@ import { SubscribeForm } from "./form";
111
112
 
112
113
  export default function Page() {
113
114
  return (
114
- <Action action={subscribeAction} initialData="">
115
+ <Action action={subscribeAction}>
115
116
  <SubscribeForm />
116
117
  </Action>
117
118
  );
@@ -226,7 +227,7 @@ export default function Page({
226
227
  const { userId } = await params;
227
228
 
228
229
  return (
229
- <Action action={updateUser} args={[await locale(), userId]} initialData="">
230
+ <Action action={updateUser} args={[await locale(), userId]} >
230
231
  <UpdateUserForm />
231
232
  </Action>
232
233
  );
@@ -298,7 +299,6 @@ export function SignUpAction({ children }: PropsWithChildren) {
298
299
  return (
299
300
  <Action
300
301
  action={signUp}
301
- initialData={undefined}
302
302
  validate={(formData) => {
303
303
  const result = zfd.formData(signUpSchema).safeParse(formData);
304
304
 
@@ -327,7 +327,6 @@ export function SignUpAction({ children }: PropsWithChildren) {
327
327
  return (
328
328
  <Action
329
329
  action={signUp}
330
- initialData={undefined}
331
330
  validate={validateSchema(signUpSchema)}
332
331
  >
333
332
  {children}
@@ -352,7 +351,6 @@ export function UpdateUserAction({ children }: PropsWithChildren) {
352
351
  return (
353
352
  <Action
354
353
  action={updateUser}
355
- initialData={undefined}
356
354
  >
357
355
  {/* IMPORTANT: must be rendered as a child of the <Action /> context. */}
358
356
  <ResetAction />
@@ -396,6 +394,56 @@ export function UpdateUserForm() {
396
394
  }
397
395
  ```
398
396
 
397
+ ### `<Submit>`
398
+
399
+ A render prop component for submit buttons. It combines the action pending state (from the `<Action>` context) with the native `useFormStatus()` of the enclosing `<form>`.
400
+
401
+ ⚠️ Must be rendered within a `<form>` (e.g. the `<Form>` component) which is a descendant of `<Action>`.
402
+
403
+ The render prop receives the `FormStatus` fields (`pending`, `data`, `method`, `action`) and an additional `disabled` flag, which is `true` while the **action** is pending.
404
+
405
+ ```tsx
406
+ import type { ReactNode } from "react";
407
+ import { Action, Form, Submit } from "react-form-action/client";
408
+
409
+
410
+ // 👉 Use the <Submit> to define your custom SubmitButton:
411
+ function SubmitButton({
412
+ children,
413
+ pendingLabel,
414
+ }: {
415
+ children: ReactNode;
416
+ pendingLabel: string;
417
+ }) {
418
+ return (
419
+ <Submit>
420
+ {({ pending, disabled }) => (
421
+ // 👉 `disabled` reflects the action state, `pending` the form submission
422
+ <button type="submit" disabled={disabled}>
423
+ {pending ? pendingLabel : children}
424
+ </button>
425
+ )}
426
+ </Submit>
427
+ );
428
+ }
429
+
430
+ // 👉 on submit, both buttons will be disabled but only the submitted one will have the pending label
431
+ function DecisionForm() {
432
+ return (
433
+ <Action action={decideAction}>
434
+ <Form>
435
+ <input type="hidden" name="decision" defaultValue="accept" />
436
+ <SubmitButton pendingLabel="Accepting...">Accept</SubmitButton>
437
+ </Form>
438
+ <Form>
439
+ <input type="hidden" name="decision" defaultValue="reject" />
440
+ <SubmitButton pendingLabel="Rejecting...">Reject</SubmitButton>
441
+ </Form>
442
+ </Action>
443
+ );
444
+ }
445
+ ```
446
+
399
447
  ### Context Bound Components `createComponents()`
400
448
 
401
449
  Use the `createComponents(action)` helper to create components which use the ActionContext and have types bound to the action type.
@@ -435,7 +483,7 @@ const { FieldError } = createComponents(signUpAction);
435
483
 
436
484
  export function SignUpForm() {
437
485
  return (
438
- <Action action={signUpAction} initialData={null}>
486
+ <Action action={signUpAction}>
439
487
  <Form>
440
488
  {/* 1️⃣ When the "name" prop is an empty string, the top-level error will be rendered e.g.:
441
489
  "Passwords don't match" */}
@@ -570,8 +618,6 @@ function SubmitButton() {
570
618
  };
571
619
  ```
572
620
 
573
-
574
-
575
621
  ### Action Creator
576
622
 
577
623
  Low-level action creator, which provides the `success`, `failure` and `invalid` envelope constructors. With the `createFormAction` you must handle the native `FormData` by yourself.
package/dist/client.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { a as FormAction, c as SuccessState, i as FailureState, o as InitialState, r as ActionState, s as InvalidState, t as Flatten } from "./formAction-0eiUHrXx.mjs";
2
- import React$1, { JSX, PropsWithChildren } from "react";
1
+ import { a as FormAction, c as SuccessState, i as FailureState, o as InitialState, r as ActionState, s as InvalidState, t as Flatten } from "./formAction-CGw5j857.mjs";
2
+ import React$1, { JSX, PropsWithChildren, ReactNode } from "react";
3
+ import { FormStatus } from "react-dom";
3
4
  import { $ZodErrorTree } from "zod/v4/core";
4
- //#region src/Action.d.ts
5
- type ActionProps<Data, Error, ValidationError, Arguments extends unknown[] = []> = PropsWithChildren<{
5
+ export type ActionProps<Data, Error, ValidationError, Arguments extends unknown[] = []> = PropsWithChildren<{
6
6
  /**
7
7
  * Whether the form action should automatically reset when unmounted.
8
8
  */
@@ -14,7 +14,7 @@ type ActionProps<Data, Error, ValidationError, Arguments extends unknown[] = []>
14
14
  */
15
15
  validate?: (payload: FormData) => ValidationError | undefined | null;
16
16
  permalink?: string;
17
- initialData: Data;
17
+ initialData?: Data;
18
18
  } & (Arguments extends [unknown, ...unknown[]] ? {
19
19
  action: FormAction<Data, Error, ValidationError, FormData, Arguments>;
20
20
  args: Arguments;
@@ -28,7 +28,7 @@ type ActionStatusFlags<T extends ActionState<unknown, unknown, unknown>["type"]
28
28
  isFailure: T extends "failure" ? true : false;
29
29
  isSuccess: T extends "success" ? true : false;
30
30
  };
31
- type ActionContextState<T extends ActionState<unknown, unknown, unknown>> = Flatten<T & ActionStatusFlags<T["type"]> & {
31
+ export type ActionContextState<T extends ActionState<unknown, unknown, unknown>> = Flatten<T & ActionStatusFlags<T["type"]> & {
32
32
  /**
33
33
  * The dispatch function returned from React.useActionState()
34
34
  */
@@ -42,40 +42,36 @@ type ActionContextState<T extends ActionState<unknown, unknown, unknown>> = Flat
42
42
  /**
43
43
  * NOTE: ActionContextState<ActionState<...>> would not allow discriminate the union inside of the ActionState.
44
44
  */
45
- type SpreadActionContext<Data = unknown, Error = unknown, ValidationError = unknown> = ActionContextState<InitialState<Data>> | ActionContextState<InvalidState<ValidationError>> | ActionContextState<FailureState<Error>> | ActionContextState<SuccessState<Data>>;
45
+ export type SpreadActionContext<Data = unknown, Error = unknown, ValidationError = unknown> = ActionContextState<InitialState<Data>> | ActionContextState<InvalidState<ValidationError>> | ActionContextState<FailureState<Error>> | ActionContextState<SuccessState<Data>>;
46
46
  /**
47
47
  * A hook to consume the form action state from the context.
48
48
  */
49
- declare function useActionContext<Data, Error, ValidationError, Args extends unknown[] = []>(_action?: FormAction<Data, Error, ValidationError, FormData, Args>): SpreadActionContext<Data, Error, ValidationError>;
50
- declare function Action<Data, Error, ValidationError, Args extends unknown[] = []>({ children, action: formAction, initialData, args, permalink, validate, autoReset }: ActionProps<Data, Error, ValidationError, Args>): import("react").JSX.Element;
51
- //#endregion
52
- //#region src/ZodFieldError.d.ts
49
+ export declare function useActionContext<Data, Error, ValidationError, Args extends unknown[] = []>(_action?: FormAction<Data, Error, ValidationError, FormData, Args>): SpreadActionContext<Data, Error, ValidationError>;
50
+ export declare function Action<Data, Error, ValidationError, Args extends unknown[] = []>({ children, action: formAction, initialData, args, permalink, validate, autoReset }: ActionProps<Data, Error, ValidationError, Args>): import("react").JSX.Element;
53
51
  declare const SEPARATOR: ".";
54
- type Paths<Shape extends $ZodErrorTree<object>, Props = Required<NonNullable<Shape["properties"]>>> = { [k in keyof Props]: k extends string ? NonNullable<Props[k]> extends $ZodErrorTree<object> ? "properties" extends keyof NonNullable<Props[k]> ? `${k}${typeof SEPARATOR}${Paths<NonNullable<Props[k]>>}` : k : k : never; }[keyof Props];
55
- type InferZodErrorPaths<T> = T extends $ZodErrorTree<object> ? Paths<T> : never;
56
- type ZodFieldErrorProps<Errors extends $ZodErrorTree<unknown>, Name extends "" | InferZodErrorPaths<Errors>> = {
52
+ export type Paths<Shape extends $ZodErrorTree<object>, Props = Required<NonNullable<Shape["properties"]>>> = { [k in keyof Props]: k extends string ? NonNullable<Props[k]> extends $ZodErrorTree<object> ? "properties" extends keyof NonNullable<Props[k]> ? `${k}${typeof SEPARATOR}${Paths<NonNullable<Props[k]>>}` : k : k : never; }[keyof Props];
53
+ export type InferZodErrorPaths<T> = T extends $ZodErrorTree<object> ? Paths<T> : never;
54
+ export type ZodFieldErrorProps<Errors extends $ZodErrorTree<unknown>, Name extends "" | InferZodErrorPaths<Errors>> = {
57
55
  errors: Errors;
58
56
  name: Name;
59
57
  children?: (props: ZodFieldErrorChildrenProps<Name>) => React$1.ReactNode;
60
58
  };
61
- type ZodFieldErrorChildrenProps<Name> = {
59
+ export type ZodFieldErrorChildrenProps<Name> = {
62
60
  name: Name;
63
61
  error?: string;
64
62
  errors: readonly string[];
65
63
  };
66
- declare const noError: Readonly<{
64
+ export declare const noError: Readonly<{
67
65
  errors: readonly string[];
68
66
  }>;
69
- declare function ZodFieldError<Errors extends $ZodErrorTree<object>, Name extends "" | InferZodErrorPaths<Errors> = "">({ errors, name, children }: ZodFieldErrorProps<Errors, Name>): React$1.ReactNode;
70
- //#endregion
71
- //#region src/createComponents.d.ts
67
+ export declare function ZodFieldError<Errors extends $ZodErrorTree<object>, Name extends "" | InferZodErrorPaths<Errors> = "">({ errors, name, children }: ZodFieldErrorProps<Errors, Name>): React$1.ReactNode;
72
68
  type ErrorProps = ZodFieldErrorChildrenProps<string>;
73
69
  type Reducers<State = unknown> = Record<string, (state: State, errorProps: ErrorProps) => unknown>;
74
70
  type InferFieldProps<T extends Reducers<any>> = { [K in keyof T]: ReturnType<T[K]>; };
75
71
  /**
76
72
  * Creates a typed components for actions created with the formAction builder.
77
73
  */
78
- declare function createComponents<Data, Error, ValidationError extends $ZodErrorTree<any>, Args extends unknown[] = [], FieldReducers extends Reducers<SpreadActionContext<Data, Error, ValidationError>> = Reducers<SpreadActionContext<Data, Error, ValidationError>>>(action: FormAction<Data, Error, ValidationError, FormData, Args>, options?: {
74
+ export declare function createComponents<Data, Error, ValidationError extends $ZodErrorTree<any>, Args extends unknown[] = [], FieldReducers extends Reducers<SpreadActionContext<Data, Error, ValidationError>> = Reducers<SpreadActionContext<Data, Error, ValidationError>>>(action: FormAction<Data, Error, ValidationError, FormData, Args>, options?: {
79
75
  fieldProps?: FieldReducers;
80
76
  }): {
81
77
  FieldError: <Name extends "" | InferZodErrorPaths<ValidationError>>({ name, children }: {
@@ -111,9 +107,7 @@ declare function createComponents<Data, Error, ValidationError extends $ZodError
111
107
  value: string;
112
108
  } & React$1.InputHTMLAttributes<HTMLInputElement>) => React$1.JSX.Element;
113
109
  };
114
- //#endregion
115
- //#region src/Form.d.ts
116
- type FormProps = Omit<JSX.IntrinsicElements["form"], "action"> & {
110
+ export type FormProps = Omit<JSX.IntrinsicElements["form"], "action"> & {
117
111
  /**
118
112
  * Opt-in into automatic form reset by using the form "action" prop.
119
113
  * By default, the onSubmit with a custom transition which opts-out of the implicit form reset.
@@ -122,26 +116,38 @@ type FormProps = Omit<JSX.IntrinsicElements["form"], "action"> & {
122
116
  */
123
117
  autoReset?: boolean;
124
118
  };
125
- declare function Form({ autoReset, ...props }: FormProps): JSX.Element;
126
- //#endregion
127
- //#region src/Pending.d.ts
119
+ export declare function Form({ autoReset, ...props }: FormProps): JSX.Element;
128
120
  /**
129
121
  * Conditionally renders the children, when the form action is in the "pending" state.
130
122
  */
131
- declare function Pending({ children }: PropsWithChildren | {
123
+ export declare function Pending({ children }: PropsWithChildren | {
132
124
  children?: (props: {
133
125
  isPending: boolean;
134
126
  }) => React.ReactNode;
135
127
  }): import("react").ReactNode;
136
- //#endregion
137
- //#region src/useResetAction.d.ts
128
+ type SubmitChildrenProps = FormStatus & {
129
+ /**
130
+ * Whether the **action** is pending. It will disable the submit button when true.
131
+ */
132
+ disabled: boolean;
133
+ };
134
+ type SubmitProps = {
135
+ /**
136
+ * A render prop to render the submit button.
137
+ */
138
+ children: (props: SubmitChildrenProps) => ReactNode;
139
+ };
140
+ /**
141
+ * A submit status component that tracks both the action & form pending states.
142
+ * NOTE: must be rendered within a <form>.
143
+ */
144
+ export declare function Submit({ children }: SubmitProps): ReactNode;
138
145
  /**
139
146
  * Hook to automatically reset the action when the component unmounts, unless it is in the initial state.
140
147
  */
141
- declare function useResetAction(): void;
148
+ export declare function useResetAction(): void;
142
149
  /**
143
150
  * Component that automatically resets the action when it unmounts, unless it is in the initial state.
144
151
  */
145
- declare function ResetAction(): null;
146
- //#endregion
147
- export { Action, ActionContextState, ActionProps, Form, FormProps, InferZodErrorPaths, Paths, Pending, ResetAction, SpreadActionContext, ZodFieldError, ZodFieldErrorChildrenProps, ZodFieldErrorProps, createComponents, noError, useActionContext, useResetAction };
152
+ export declare function ResetAction(): null;
153
+ export {};
package/dist/client.mjs CHANGED
@@ -1 +1 @@
1
- "use client";import{n as e,t}from"./createFormAction-BwMYAzm2.mjs";import{createContext as n,startTransition as r,use as i,useActionState as a,useCallback as o,useEffect as s}from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";function d(){let{reset:e,isInitial:t}=h();s(()=>()=>{t||e()},[t,e])}function f(){return d(),null}const p={isInitial:!1,isInvalid:!1,isFailure:!1,isSuccess:!1},m=n(null);function h(e){let t=i(m);if(!t)throw Error(`ActionContext must be initialized before use. Is your useActionContext hook wrapped with an <Action> Component?`);return t}function g({children:n,action:i,initialData:s,args:c,permalink:d,validate:h,autoReset:g=!0}){let _=c?i.bind(null,...c):i,[v,y,b]=a(async(n,r)=>{if(r===null)return e(s);if(h){let e=await t(({invalid:e,success:t})=>async(n,r)=>{let i=h(r);return i?e(i):t(!0)})(n,r);if(e.type===`invalid`)return e}return _(n,r)},e(s),d),x={action:y,reset:o(()=>{r(()=>{y(null)})},[y]),isPending:b},S=v.type===`initial`?{...x,...v,...p,isInitial:!0}:v.type===`invalid`?{...x,...v,...p,isInvalid:!0}:v.type===`failure`?{...x,...v,...p,isFailure:!0}:{...x,...v,...p,isSuccess:!0};return u(m,{value:S,children:[g&&l(f,{}),n]})}const _=Object.freeze({errors:Object.freeze([])});function v({errors:e,name:t,children:n=({error:e})=>l(c,{children:e})}){if(t.length===0)return n({name:t,error:e.errors[0],errors:e.errors});let r=t.split(`.`),i=e;for(let e of r){if(!i.properties){i=_;break}i=i.properties[e]??_}return n({name:t,error:i.errors[0],errors:i.errors})}function y(e,t={}){function n({name:e,value:t,...n}){return l(`input`,{type:`hidden`,name:e,defaultValue:t,...n})}function r({name:n,children:r}){let i=h(e),{isInvalid:a,validationError:o}=i,s=r??(({error:e})=>a&&l(c,{children:e}));return l(v,{errors:o??_,name:n,children:e=>{let n=Object.fromEntries(Object.entries(t.fieldProps??{}).map(([t,n])=>[t,n(i,e)]));return s({...e,...n})}})}function i({children:t}){let{isFailure:n,error:r}=h(e);return n?typeof t==`function`?t({isFailure:n,error:r}):t:null}function a({children:t}){let{isSuccess:n,data:r}=h(e);return typeof t==`function`?t({isSuccess:n,data:r}):n&&t}function o({children:t}){let{isInvalid:n,validationError:r}=h(e);return typeof t==`function`?t({isInvalid:n,validationError:r}):n&&t}return{FieldError:r,Failure:i,Success:a,Invalid:o,Value:n}}function b({autoReset:e=!1,...t}){let{action:n}=h();return l(`form`,{...e?{action:n}:{onSubmit:e=>{e.preventDefault();let t=e.currentTarget;r(()=>{n(new FormData(t))})}},...t})}function x({children:e}){let{isPending:t}=h();return typeof e==`function`?e({isPending:t}):t&&e}export{g as Action,b as Form,x as Pending,f as ResetAction,v as ZodFieldError,y as createComponents,_ as noError,h as useActionContext,d as useResetAction};
1
+ "use client";import{n as e,t}from"./createFormAction-BwMYAzm2.mjs";import{createContext as n,startTransition as r,use as i,useActionState as a,useCallback as o,useEffect as s}from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";import{useFormStatus as d}from"react-dom";function f(){let{reset:e,isInitial:t}=g();s(()=>()=>{t||e()},[t,e])}function p(){return f(),null}const m={isInitial:!1,isInvalid:!1,isFailure:!1,isSuccess:!1},h=n(null);function g(e){let t=i(h);if(!t)throw Error(`ActionContext must be initialized before use. Is your useActionContext hook wrapped with an <Action> Component?`);return t}function _({children:n,action:i,initialData:s,args:c,permalink:d,validate:f,autoReset:g=!0}){let _=c?i.bind(null,...c):i,[v,y,b]=a(async(n,r)=>{if(r===null)return e(s);if(f){let e=await t(({invalid:e,success:t})=>async(n,r)=>{let i=f(r);return i?e(i):t(!0)})(n,r);if(e.type===`invalid`)return e}return _(n,r)},e(s),d),x={action:y,reset:o(()=>{r(()=>{y(null)})},[y]),isPending:b},S=v.type===`initial`?{...x,...v,...m,isInitial:!0}:v.type===`invalid`?{...x,...v,...m,isInvalid:!0}:v.type===`failure`?{...x,...v,...m,isFailure:!0}:{...x,...v,...m,isSuccess:!0};return/* @__PURE__ */ u(h,{value:S,children:[g&&/* @__PURE__ */ l(p,{}),n]})}const v=Object.freeze({errors:Object.freeze([])});function y({errors:e,name:t,children:n=({error:e})=>/* @__PURE__ */ l(c,{children:e})}){if(t.length===0)return n({name:t,error:e.errors[0],errors:e.errors});let r=t.split(`.`),i=e;for(let e of r){if(!i.properties){i=v;break}i=i.properties[e]??v}return n({name:t,error:i.errors[0],errors:i.errors})}function b(e,t={}){function n({name:e,value:t,...n}){return/* @__PURE__ */ l(`input`,{type:`hidden`,name:e,defaultValue:t,...n})}function r({name:n,children:r}){let i=g(e),{isInvalid:a,validationError:o}=i,s=r??(({error:e})=>a&&/* @__PURE__ */ l(c,{children:e}));return/* @__PURE__ */ l(y,{errors:o??v,name:n,children:e=>{let n=Object.fromEntries(Object.entries(t.fieldProps??{}).map(([t,n])=>[t,n(i,e)]));return s({...e,...n})}})}function i({children:t}){let{isFailure:n,error:r}=g(e);return n?typeof t==`function`?t({isFailure:n,error:r}):t:null}function a({children:t}){let{isSuccess:n,data:r}=g(e);return typeof t==`function`?t({isSuccess:n,data:r}):n&&t}function o({children:t}){let{isInvalid:n,validationError:r}=g(e);return typeof t==`function`?t({isInvalid:n,validationError:r}):n&&t}return{FieldError:r,Failure:i,Success:a,Invalid:o,Value:n}}function x({autoReset:e=!1,...t}){let{action:n}=g();return/* @__PURE__ */ l(`form`,{...e?{action:n}:{onSubmit:e=>{e.preventDefault();let t=e.currentTarget;r(()=>{n(new FormData(t))})}},...t})}function S({children:e}){let{isPending:t}=g();return typeof e==`function`?e({isPending:t}):t&&e}function C({children:e}){let{isPending:t}=g();return e({...d(),disabled:t})}export{_ as Action,x as Form,S as Pending,p as ResetAction,C as Submit,y as ZodFieldError,b as createComponents,v as noError,g as useActionContext,f as useResetAction};
@@ -1,6 +1,5 @@
1
1
  import { ZodObject, ZodTuple, ZodType, z } from "zod/v4";
2
2
  import { $ZodErrorTree, $ZodShape, $ZodType } from "zod/v4/core";
3
- //#region src/createFormAction.d.ts
4
3
  type InitialState<T> = {
5
4
  type: "initial";
6
5
  data: T;
@@ -33,8 +32,6 @@ declare function createFormAction<Data, Error = Data, ValidationError = Record<s
33
32
  failure: (error: Error) => FailureState<Error>;
34
33
  invalid: (validationError: ValidationError) => InvalidState<ValidationError>;
35
34
  }, ...args: Arguments) => FormAction<Data, Error, ValidationError, Payload>): (...args: [...Arguments, state: ActionState<Data, Error, ValidationError>, payload: Payload]) => Promise<ActionState<Data, Error, ValidationError>>;
36
- //#endregion
37
- //#region src/formAction.d.ts
38
35
  declare const emptyInput: unique symbol;
39
36
  type EmptyInput = typeof emptyInput;
40
37
  type Flatten<T> = Identity<{ [K in keyof T]: T[K]; }>;
@@ -86,5 +83,4 @@ type FormActionBuilder<Schema extends ZodType | EmptyInput, Args extends $ZodTyp
86
83
  error: <TErr>(processError: ErrorHandler<Context, TErr, PlainArgs>) => FormActionBuilder<Schema, Args, TErr, Context>;
87
84
  };
88
85
  declare const formAction: FormActionBuilder<typeof emptyInput, [], unknown, InitialContext, []>;
89
- //#endregion
90
86
  export { FormAction as a, SuccessState as c, FailureState as i, createFormAction as l, formAction as n, InitialState as o, ActionState as r, InvalidState as s, Flatten as t, initial as u };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,9 @@
1
- import { a as FormAction, c as SuccessState, i as FailureState, l as createFormAction, n as formAction, o as InitialState, r as ActionState, s as InvalidState, t as Flatten, u as initial } from "./formAction-0eiUHrXx.mjs";
1
+ import { a as FormAction, c as SuccessState, i as FailureState, l as createFormAction, n as formAction, o as InitialState, r as ActionState, s as InvalidState, t as Flatten, u as initial } from "./formAction-CGw5j857.mjs";
2
2
  import { ZodObject, z } from "zod";
3
- //#region src/validateSchema.d.ts
4
3
  /**
5
4
  * A helper to make a validate function for the client validation with <Action validate={} /> prop.
6
5
  * @param schema z.object(...) schema
7
6
  * @returns validate function
8
7
  */
9
- declare function validateSchema<T extends ZodObject>(schema: T): (formData: FormData) => z.core.$ZodErrorTree<z.infer<T>, string> | null;
10
- //#endregion
11
- export { ActionState, FailureState, Flatten, FormAction, InitialState, InvalidState, SuccessState, createFormAction, formAction, initial, validateSchema };
8
+ export declare function validateSchema<T extends ZodObject>(schema: T): (formData: FormData) => z.core.$ZodErrorTree<z.infer<T>, string> | null;
9
+ export { ActionState, FailureState, Flatten, FormAction, InitialState, InvalidState, SuccessState, createFormAction, formAction, initial };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-form-action",
3
- "version": "2.18.0",
3
+ "version": "2.19.1",
4
4
  "description": "State management helpers for the react form actions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -57,22 +57,22 @@
57
57
  "zod-form-data": "^3.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@biomejs/biome": "^2.5.11",
61
- "@testing-library/dom": "^10.4.1",
60
+ "@biomejs/biome": "^2.6.6",
61
+ "@testing-library/dom": "^10.4.2",
62
62
  "@testing-library/jest-dom": "^7.0.1",
63
63
  "@testing-library/react": "^16.3.3",
64
- "@testing-library/user-event": "^14.6.6",
65
- "@types/react": "^19.2.18",
66
- "@types/react-dom": "^19.2.5",
67
- "@vitejs/plugin-react": "^6.1.1",
68
- "happy-dom": "^20.12.0",
69
- "npm-check-updates": "^23.1.0",
70
- "react": "^19.2.8",
71
- "react-dom": "^19.2.8",
72
- "tsdown": "^0.22.14",
64
+ "@testing-library/user-event": "^14.6.8",
65
+ "@types/react": "^19.3.0",
66
+ "@types/react-dom": "^19.3.0",
67
+ "@vitejs/plugin-react": "^6.2.1",
68
+ "happy-dom": "^21.0.4",
69
+ "npm-check-updates": "^23.1.1",
70
+ "react": "^19.3.1",
71
+ "react-dom": "^19.3.1",
72
+ "tsdown": "^0.23.7",
73
73
  "typescript": "^7.0.2",
74
- "vitest": "^4.1.11",
75
- "zod": "^4.5.4",
76
- "zod-form-data": "^3.0.3"
74
+ "vitest": "^5.1.0",
75
+ "zod": "^4.6.7",
76
+ "zod-form-data": "^3.0.4"
77
77
  }
78
78
  }