react-form-action 2.14.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/README.md +1 -0
- package/dist/client.d.mts +4 -0
- package/dist/client.mjs +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ End-to-end typesafe success, error & validation state control for Next.js form a
|
|
|
23
23
|
- ✅ Computes progress flags like `isInvalid`, `isSuccess` based on the envelope type.
|
|
24
24
|
- ✅ Binds the action with the arguments from the _args_ prop.
|
|
25
25
|
- ✅ Has an optional `validate` prop to validate the form data client-side before calling the server action.
|
|
26
|
+
- ✅ Enables you to reset the action state with the `reset()` callback.
|
|
26
27
|
|
|
27
28
|
**Context-bound `<Form />` component**
|
|
28
29
|
|
package/dist/client.d.mts
CHANGED
|
@@ -26,6 +26,10 @@ type ActionContextState<T extends ActionState<unknown, unknown, unknown>> = Flat
|
|
|
26
26
|
* The dispatch function returned from React.useActionState()
|
|
27
27
|
*/
|
|
28
28
|
action: (payload: FormData) => void;
|
|
29
|
+
/**
|
|
30
|
+
* A function to reset the form action state to its initial state.
|
|
31
|
+
*/
|
|
32
|
+
reset: () => void;
|
|
29
33
|
isPending: boolean;
|
|
30
34
|
}>;
|
|
31
35
|
/**
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-action",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.1",
|
|
4
4
|
"description": "State management helpers for the react form actions.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
"zod-form-data": "^3.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@biomejs/biome": "^2.5.
|
|
60
|
+
"@biomejs/biome": "^2.5.10",
|
|
61
61
|
"@testing-library/dom": "^10.4.1",
|
|
62
62
|
"@testing-library/jest-dom": "^7.0.1",
|
|
63
63
|
"@testing-library/react": "^16.3.2",
|
|
64
|
-
"@testing-library/user-event": "^14.6.
|
|
64
|
+
"@testing-library/user-event": "^14.6.6",
|
|
65
65
|
"@types/react": "^19.2.18",
|
|
66
|
-
"@types/react-dom": "^19.2.
|
|
67
|
-
"@vitejs/plugin-react": "^6.0
|
|
68
|
-
"happy-dom": "^20.11.
|
|
69
|
-
"npm-check-updates": "^23.0
|
|
66
|
+
"@types/react-dom": "^19.2.5",
|
|
67
|
+
"@vitejs/plugin-react": "^6.1.0",
|
|
68
|
+
"happy-dom": "^20.11.8",
|
|
69
|
+
"npm-check-updates": "^23.1.0",
|
|
70
70
|
"react": "^19.2.8",
|
|
71
71
|
"react-dom": "^19.2.8",
|
|
72
72
|
"tsdown": "^0.22.14",
|
|
73
73
|
"typescript": "^7.0.2",
|
|
74
|
-
"vitest": "^4.1.
|
|
74
|
+
"vitest": "^4.1.11",
|
|
75
75
|
"zod": "^4.4.3",
|
|
76
76
|
"zod-form-data": "^3.0.3"
|
|
77
77
|
}
|