react-form-action 2.18.0 → 2.19.0
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/client.d.mts +22 -2
- package/dist/client.mjs +1 -1
- package/package.json +1 -1
package/dist/client.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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";
|
|
2
|
+
import React$1, { JSX, PropsWithChildren, ReactNode } from "react";
|
|
3
|
+
import { FormStatus } from "react-dom";
|
|
3
4
|
import { $ZodErrorTree } from "zod/v4/core";
|
|
4
5
|
//#region src/Action.d.ts
|
|
5
6
|
type ActionProps<Data, Error, ValidationError, Arguments extends unknown[] = []> = PropsWithChildren<{
|
|
@@ -134,6 +135,25 @@ declare function Pending({ children }: PropsWithChildren | {
|
|
|
134
135
|
}) => React.ReactNode;
|
|
135
136
|
}): import("react").ReactNode;
|
|
136
137
|
//#endregion
|
|
138
|
+
//#region src/Submit.d.ts
|
|
139
|
+
type SubmitChildrenProps = FormStatus & {
|
|
140
|
+
/**
|
|
141
|
+
* Whether the **action** is pending. It will disable the submit button when true.
|
|
142
|
+
*/
|
|
143
|
+
disabled: boolean;
|
|
144
|
+
};
|
|
145
|
+
type SubmitProps = {
|
|
146
|
+
/**
|
|
147
|
+
* A render prop to render the submit button.
|
|
148
|
+
*/
|
|
149
|
+
children: (props: SubmitChildrenProps) => ReactNode;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* A submit status component that tracks both the action & form pending states.
|
|
153
|
+
* NOTE: must be rendered within a <form>.
|
|
154
|
+
*/
|
|
155
|
+
declare function Submit({ children }: SubmitProps): ReactNode;
|
|
156
|
+
//#endregion
|
|
137
157
|
//#region src/useResetAction.d.ts
|
|
138
158
|
/**
|
|
139
159
|
* Hook to automatically reset the action when the component unmounts, unless it is in the initial state.
|
|
@@ -144,4 +164,4 @@ declare function useResetAction(): void;
|
|
|
144
164
|
*/
|
|
145
165
|
declare function ResetAction(): null;
|
|
146
166
|
//#endregion
|
|
147
|
-
export { Action, ActionContextState, ActionProps, Form, FormProps, InferZodErrorPaths, Paths, Pending, ResetAction, SpreadActionContext, ZodFieldError, ZodFieldErrorChildrenProps, ZodFieldErrorProps, createComponents, noError, useActionContext, useResetAction };
|
|
167
|
+
export { Action, ActionContextState, ActionProps, Form, FormProps, InferZodErrorPaths, Paths, Pending, ResetAction, SpreadActionContext, Submit, ZodFieldError, ZodFieldErrorChildrenProps, ZodFieldErrorProps, createComponents, noError, useActionContext, useResetAction };
|
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
|
|
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 u(h,{value:S,children:[g&&l(p,{}),n]})}const v=Object.freeze({errors:Object.freeze([])});function y({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=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 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&&l(c,{children:e}));return 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 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};
|