mtxuilib 0.0.458 → 0.0.460

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