react-form-action 2.7.0 → 2.8.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/README.md +5 -3
- package/dist/client.d.mts +20 -5
- package/dist/client.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,10 +223,12 @@ export default function Page({
|
|
|
223
223
|
const locale = await localeParam();
|
|
224
224
|
const { userId } = await params;
|
|
225
225
|
|
|
226
|
-
const action = updateUser.bind(null, userId, locale);
|
|
227
|
-
|
|
228
226
|
return (
|
|
229
|
-
<Action
|
|
227
|
+
<Action
|
|
228
|
+
action={updateUser}
|
|
229
|
+
args={[userId, await localeParam()]}
|
|
230
|
+
initialData=""
|
|
231
|
+
>
|
|
230
232
|
<SubscribeForm />
|
|
231
233
|
</Action>
|
|
232
234
|
);
|
package/dist/client.d.mts
CHANGED
|
@@ -3,10 +3,16 @@ import React__default, { PropsWithChildren, JSX } from 'react';
|
|
|
3
3
|
import { F as FormAction, A as ActionState, I as InitialState, a as InvalidState, b as FailureState, S as SuccessState } from './createFormAction-DjhozgiG.mjs';
|
|
4
4
|
import { $ZodErrorTree } from 'zod/v4/core';
|
|
5
5
|
|
|
6
|
-
type ActionProps<Data, Error, ValidationError> = PropsWithChildren<{
|
|
7
|
-
action: FormAction<Data, Error, ValidationError>;
|
|
6
|
+
type ActionProps<Data, Error, ValidationError, Arguments extends unknown[] = []> = PropsWithChildren<Arguments extends [unknown] ? {
|
|
7
|
+
action: FormAction<Data, Error, ValidationError, FormData, Arguments>;
|
|
8
|
+
args: Arguments;
|
|
8
9
|
initialData: Data;
|
|
9
10
|
permalink?: string;
|
|
11
|
+
} : {
|
|
12
|
+
action: FormAction<Data, Error, ValidationError, FormData, Arguments>;
|
|
13
|
+
initialData: Data;
|
|
14
|
+
args?: undefined;
|
|
15
|
+
permalink?: string;
|
|
10
16
|
}>;
|
|
11
17
|
type ActionStatusFlags<T extends ActionState<unknown, unknown, unknown>["type"] | unknown = unknown> = {
|
|
12
18
|
isInitial: T extends "initial" ? true : false;
|
|
@@ -28,8 +34,8 @@ type SpreadActionContext<Data = unknown, Error = unknown, ValidationError = unkn
|
|
|
28
34
|
/**
|
|
29
35
|
* A hook to consume the form action state from the context.
|
|
30
36
|
*/
|
|
31
|
-
declare function useActionContext<Data, Error, ValidationError>(action?: FormAction<Data, Error, ValidationError>): SpreadActionContext<Data, Error, ValidationError>;
|
|
32
|
-
declare function Action<Data, Error, ValidationError>({ children, action: formAction, initialData, permalink, }: ActionProps<Data, Error, ValidationError>): React__default.JSX.Element;
|
|
37
|
+
declare function useActionContext<Data, Error, ValidationError, Args extends unknown[] = []>(action?: FormAction<Data, Error, ValidationError, FormData, Args>): SpreadActionContext<Data, Error, ValidationError>;
|
|
38
|
+
declare function Action<Data, Error, ValidationError, Args extends unknown[] = []>({ children, action: formAction, initialData, args, permalink, }: ActionProps<Data, Error, ValidationError, Args>): React__default.JSX.Element;
|
|
33
39
|
|
|
34
40
|
type FormProps = Omit<JSX.IntrinsicElements["form"], "action"> & {
|
|
35
41
|
/**
|
|
@@ -65,7 +71,7 @@ declare function ZodFieldError<Errors extends $ZodErrorTree<object>, Name extend
|
|
|
65
71
|
/**
|
|
66
72
|
* Creates a typed components for actions created with the formAction builder.
|
|
67
73
|
*/
|
|
68
|
-
declare function createComponents<Data, Error, ValidationError extends $ZodErrorTree<any
|
|
74
|
+
declare function createComponents<Data, Error, ValidationError extends $ZodErrorTree<any>, Args extends unknown[] = []>(action: FormAction<Data, Error, ValidationError, FormData, Args>): {
|
|
69
75
|
FieldError: <Name extends "" | InferZodErrorPaths<ValidationError>>({ name, children, }: {
|
|
70
76
|
name: Name;
|
|
71
77
|
children?: (props: ZodFieldErrorChildrenProps<Name>) => React__default.ReactNode;
|
|
@@ -79,6 +85,15 @@ declare function createComponents<Data, Error, ValidationError extends $ZodError
|
|
|
79
85
|
data: Data;
|
|
80
86
|
}) => React__default.ReactNode;
|
|
81
87
|
}) => React__default.ReactNode;
|
|
88
|
+
Invalid: ({ children, }: PropsWithChildren | {
|
|
89
|
+
children?: (props: {
|
|
90
|
+
isInvalid: false;
|
|
91
|
+
validationError: null;
|
|
92
|
+
} | {
|
|
93
|
+
isInvalid: true;
|
|
94
|
+
validationError: ValidationError;
|
|
95
|
+
}) => React__default.ReactNode;
|
|
96
|
+
}) => React__default.ReactNode;
|
|
82
97
|
};
|
|
83
98
|
|
|
84
99
|
/**
|
package/dist/client.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a as
|
|
1
|
+
"use client";import{a as f}from"./chunk-LPB4R2UB.mjs";import S from"react";import{useActionState as F,createContext as P,use as y}from"react";var c={isInitial:!1,isInvalid:!1,isFailure:!1,isSuccess:!1},E=P(null);function s(e){let t=y(E);if(!t)throw new Error("ActionContext must be initialized before use. Is your useActionContext hook wrapped with an <Action> Component?");return t}function v({children:e,action:t,initialData:a,args:i,permalink:r}){let o=i?t.bind(null,...i):t,[n,l,d]=F(o,f(a),r),u=n.type==="initial"?{...n,...c,action:l,isPending:d,isInitial:!0}:n.type==="invalid"?{...n,...c,action:l,isPending:d,isInvalid:!0}:n.type==="failure"?{...n,...c,action:l,isPending:d,isFailure:!0}:{...n,...c,action:l,isPending:d,isSuccess:!0};return S.createElement(E,{value:u},e)}import h,{startTransition as g}from"react";function I({autoReset:e=!1,...t}){let{action:a}=s();return h.createElement("form",{...e?{action:a}:{onSubmit:r=>{r.preventDefault();let o=r.currentTarget;g(()=>{a(new FormData(o))})}},...t})}import m from"react";import x from"react";var C=".",p=Object.freeze({errors:Object.freeze([])});function A({errors:e,name:t,children:a=({error:i})=>x.createElement(x.Fragment,null,i)}){if(t.length===0)return a({name:t,error:e.errors[0],errors:e.errors});let i=t.split(C),r=e;for(;i.length;){let o=i.shift();if(!r.properties){r=p;break}r=r.properties[o]??p}return a({name:t,error:r.errors[0],errors:r.errors})}function J(e){function t({name:r,children:o}){let{isInvalid:n,validationError:l}=s(e);return m.createElement(A,{errors:l??p,name:r},o??(({error:u})=>n&&m.createElement(m.Fragment,null,u)))}function a({children:r}){let{isSuccess:o,data:n}=s(e);return typeof r=="function"?r(o?{isSuccess:o,data:n}:{isSuccess:o,data:n}):o&&r}function i({children:r}){let{isInvalid:o,validationError:n}=s(e);return typeof r=="function"?r(o?{isInvalid:o,validationError:n}:{isInvalid:o,validationError:n}):o&&r}return{FieldError:t,Success:a,Invalid:i}}function q({children:e}){let{isPending:t}=s();return typeof e=="function"?e({isPending:t}):t&&e}export{v as Action,I as Form,q as Pending,A as ZodFieldError,J as createComponents,p as noError,s as useActionContext};
|