react-form-action 2.15.0 → 2.15.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/dist/client.mjs +1 -1
- package/package.json +1 -1
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}from"react";import{Fragment as
|
|
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}from"react";import{Fragment as s,jsx as c}from"react/jsx-runtime";const l={isInitial:!1,isInvalid:!1,isFailure:!1,isSuccess:!1},u=n(null);function d(e){let t=i(u);if(!t)throw Error(`ActionContext must be initialized before use. Is your useActionContext hook wrapped with an <Action> Component?`);return t}function f({children:n,action:i,initialData:s,args:d,permalink:f,validate:p}){let m=d?i.bind(null,...d):i,[h,g,_]=a(async(n,r)=>{if(r===null)return e(s);if(p){let e=await t(({invalid:e,success:t})=>async(n,r)=>{let i=p(r);return i?e(i):t(!0)})(n,r);if(e.type===`invalid`)return e}return m(n,r)},e(s),f),v=o(()=>{r(()=>{g(null)})},[g]),y=h.type===`initial`?{...h,...l,action:g,reset:v,isPending:_,isInitial:!0}:h.type===`invalid`?{...h,...l,action:g,reset:v,isPending:_,isInvalid:!0}:h.type===`failure`?{...h,...l,action:g,reset:v,isPending:_,isFailure:!0}:{...h,...l,action:g,reset:v,isPending:_,isSuccess:!0};return c(u,{value:y,children:n})}const p=Object.freeze({errors:Object.freeze([])});function m({errors:e,name:t,children:n=({error:e})=>c(s,{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=p;break}i=i.properties[e]??p}return n({name:t,error:i.errors[0],errors:i.errors})}function h(e,t={}){function n({name:n,children:r}){let i=d(e),{isInvalid:a,validationError:o}=i,l=r??(({error:e})=>a&&c(s,{children:e}));return c(m,{errors:o??p,name:n,children:e=>{let n=Object.fromEntries(Object.entries(t.fieldProps??{}).map(([t,n])=>[t,n(i,e)]));return l({...e,...n})}})}function r({children:t}){let{isFailure:n,error:r}=d(e);return n?typeof t==`function`?t({isFailure:n,error:r}):t:null}function i({children:t}){let{isSuccess:n,data:r}=d(e);return typeof t==`function`?t({isSuccess:n,data:r}):n&&t}function a({children:t}){let{isInvalid:n,validationError:r}=d(e);return typeof t==`function`?t({isInvalid:n,validationError:r}):n&&t}return{FieldError:n,Failure:r,Success:i,Invalid:a}}function g({autoReset:e=!1,...t}){let{action:n}=d();return c(`form`,{...e?{action:n}:{onSubmit:e=>{e.preventDefault();let t=e.currentTarget;r(()=>{n(new FormData(t))})}},...t})}function _({children:e}){let{isPending:t}=d();return typeof e==`function`?e({isPending:t}):t&&e}export{f as Action,g as Form,_ as Pending,m as ZodFieldError,h as createComponents,p as noError,d as useActionContext};
|