mtxuilib 0.0.457 → 0.0.459
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ComponentProps, PropsWithChildren } from "react";
|
|
2
2
|
import type { Message, PartialMessage } from "@bufbuild/protobuf";
|
|
3
3
|
import { DecoratedMutation, DecoratedQuery } from "@trpc/react-query/dist/createTRPCReact";
|
|
4
|
+
import { UseFormProps } from "react-hook-form";
|
|
5
|
+
import { z } from "zod";
|
|
4
6
|
type ResolverDef = {
|
|
5
7
|
input: any;
|
|
6
8
|
output: any;
|
|
@@ -11,6 +13,12 @@ export declare function TrpcUpdateForm<TDef extends ResolverDef>(props: {
|
|
|
11
13
|
defaultValues?: any;
|
|
12
14
|
mutationUpdate: DecoratedMutation<TDef>;
|
|
13
15
|
} & Omit<ComponentProps<typeof FormInnerWithSuspenseQuery>, "onSubmit">): import("react").JSX.Element;
|
|
16
|
+
export declare function useTrpcUpdateForm<TSchema extends z.ZodType>(props: Omit<UseFormProps<TSchema['_input']>, 'resolver'> & {
|
|
17
|
+
schema?: TSchema;
|
|
18
|
+
}): {
|
|
19
|
+
handleSubmit: (e?: import("react").BaseSyntheticEvent<object, any, any> | undefined) => Promise<void>;
|
|
20
|
+
form: import("react-hook-form").UseFormReturn<z.TypeOf<TSchema>, any, undefined>;
|
|
21
|
+
};
|
|
14
22
|
declare function FormInner(props: {
|
|
15
23
|
defaultValues: any;
|
|
16
24
|
onSubmit: (values: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";var
|
|
1
|
+
"use client";var T=Object.defineProperty,I=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var p=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var y=(e,t,o)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,c=(e,t)=>{for(var o in t||(t={}))S.call(t,o)&&y(e,o,t[o]);if(p)for(var o of p(t))h.call(t,o)&&y(e,o,t[o]);return e},b=(e,t)=>I(e,V(t));var F=(e,t)=>{var o={};for(var r in e)S.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&p)for(var r of p(e))t.indexOf(r)<0&&h.call(e,r)&&(o[r]=e[r]);return o};var M=(e,t,o)=>new Promise((r,a)=>{var d=n=>{try{u(o.next(n))}catch(s){a(s)}},i=n=>{try{u(o.throw(n))}catch(s){a(s)}},u=n=>n.done?r(n.value):Promise.resolve(n.value).then(d,i);u((o=o.apply(e,t)).next())});import{Fragment as C,jsx as m}from"react/jsx-runtime";import{Suspense as D,useCallback as O,useMemo as U}from"react";import{Provider as k,atom as x,createStore as Q,useAtom as q}from"jotai";import{FormProvider as W,useForm as z,useFormContext as A}from"react-hook-form";import{toast as P}from"sonner";const g=x(void 0);function ee(e){const{defaultValues:t,params:o,children:r,mutationUpdate:a,queryMethod:d}=e,i=a.useMutation(),u=O(s=>M(this,null,function*(){try{const l=yield i.mutateAsync(s);P("ok",{description:JSON.stringify(l,null,2),action:{label:"Undo",onClick:()=>console.log("Undo")}})}catch(l){P("error",{description:JSON.stringify(l,null,2),action:{label:"Undo",onClick:()=>console.log("Undo")}}),console.log("\u51FA\u9519",l)}}),[i]),n=U(()=>{const s=Q();return s.set(g,()=>u),s},[u]);return m(k,{store:n,children:t?m(v,{defaultValues:t,onSubmit:u,children:r}):m(C,{children:m(D,{fallback:m(C,{children:"ConnectEsUpdateForm loading"}),children:m(w,{queryMethod:d,params:o,onSubmit:u,children:r})})})})}function te(e){const[t,o]=q(g),r=A();return{handleSubmit:r.handleSubmit(a=>t(a)),form:r}}function v(e){const{defaultValues:t,onSubmit:o,children:r}=e,a=z({defaultValues:t});return m(W,b(c({},a),{children:m("form",{onSubmit:a.handleSubmit(o),children:r})}))}function w(e){const n=e,{queryMethod:t,params:o,onSubmit:r}=n,a=F(n,["queryMethod","params","onSubmit"]),[d,i]=t.useSuspenseQuery(o),u=U(()=>{var l,f;const s=i.data;return(l=s.item)!=null&&l.value?(f=s.item)==null?void 0:f.value:i.data},[i.data]);return m(v,c({defaultValues:u,onSubmit:r},a))}export{ee as TrpcUpdateForm,te as useTrpcUpdateForm};
|