mtxuilib 0.0.404 → 0.0.406

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,7 @@
1
1
  /// <reference types="react" />
2
- import { MtUnaryCallError } from "gomtm/connectquery/utils";
2
+ import { PlainMessage } from "gomtm";
3
+ import { MtmError } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
3
4
  export declare const MtUnaryCallErrorView: (props: {
4
- unaryError: MtUnaryCallError;
5
+ unaryError: PlainMessage<MtmError>;
5
6
  retry?: () => void;
6
7
  }) => import("react").JSX.Element;
@@ -1 +1 @@
1
- "use client";import{jsx as r,jsxs as a}from"react/jsx-runtime";const d=t=>{const{unaryError:e,retry:o}=t;return a("div",{className:"bg-red-400 p-4",children:["code: ",e.error_code,r("div",{children:r("pre",{className:"prose dark:prose-invert break-words",children:e.error_message})}),o&&r("button",{onClick:()=>{o()},children:"retry"})]})};export{d as MtUnaryCallErrorView};
1
+ "use client";import{jsx as r,jsxs as s}from"react/jsx-runtime";const l=t=>{const{unaryError:e,retry:o}=t;return s("div",{className:"bg-red-400 p-4",children:["code: ",e.errCode,r("div",{children:r("pre",{className:"prose dark:prose-invert break-words",children:e.errMessage})}),o&&r("button",{onClick:()=>{o()},children:"retry"})]})};export{l as MtUnaryCallErrorView};
@@ -1,12 +1,12 @@
1
1
  import { InfiniteData, UseSuspenseInfiniteQueryResult } from "@tanstack/react-query";
2
- import type { ConnectError, Message } from "gomtm";
2
+ import type { ConnectError, Message, PlainMessage } from "gomtm";
3
3
  import { MethodUnaryDescriptor } from "gomtm/connectquery";
4
- import { MtUnaryCallError } from "gomtm/connectquery/utils";
4
+ import { MtmError } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
5
5
  import { PropsWithChildren } from "react";
6
6
  export declare function CommonListViewProvider<I extends Message<I>, O extends Message<O>>(props: {
7
7
  methodList: MethodUnaryDescriptor<I, any>;
8
8
  } & PropsWithChildren): import("react").JSX.Element;
9
9
  export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
10
10
  export declare function useCommonListView<T extends Message<T>>(): {
11
- listQuery: UseSuspenseInfiniteQueryResult<InfiniteData<T & MtUnaryCallError, unknown>, ConnectError> | null;
11
+ listQuery: UseSuspenseInfiniteQueryResult<InfiniteData<T & PlainMessage<MtmError>, unknown>, ConnectError> | null;
12
12
  };
@@ -1 +1 @@
1
- "use client";import{Fragment as k,jsx as e,jsxs as p}from"react/jsx-runtime";import{useSuspenseInfiniteQuery as y}from"gomtm/connectquery";import{ListViewLayout as m}from"gomtm/gomtmpb/mtm/sppb/mtm_pb";import{atom as f,useAtom as g}from"jotai";import{useHydrateAtoms as c}from"jotai/utils";import{ListItemView as P}from"../components/ListItem";import{MtUnaryCallErrorView as L}from"../components/MtUnaryCallErrorView";import{cn as h}from"../lib/utils";import{Pagination as I,PaginationContent as v,PaginationEllipsis as w,PaginationItem as r,PaginationLink as u,PaginationNext as x,PaginationPrevious as C}from"../ui/pagination";const l=f(null);function K(t){const{children:i,methodList:n}=t,o=y(n,{page:1},{pageParamKey:"pagination",getNextPageParam:(s,d,a)=>({page:((a==null?void 0:a.page)||0)+1})});return c([[l,o]]),e(k,{children:i})}function _(){const[t,i]=g(l);return t!=null&&t.data?p("div",{className:"relative w-full",children:[e("div",{className:h("w-full"),children:t.data.pages.map((n,o)=>{var s;return n.error_code?e(L,{unaryError:n},o):e(M,{layout:n.listLayout,children:(s=n==null?void 0:n.items)==null?void 0:s.map((d,a)=>e(P,{item:d},`${o}-${a}`))},o)})}),e(I,{children:p(v,{children:[e(r,{children:e(C,{href:"#"})}),e(r,{children:e(u,{href:"#",children:"1"})}),e(r,{children:e(u,{href:"#",isActive:!0,children:"2"})}),e(r,{children:e(u,{href:"#",children:"3"})}),e(r,{children:e(w,{})}),e(r,{children:e(x,{href:"#"})})]})}),e("div",{className:"absolute right-1 top-1"})]}):null}const M=t=>{const{children:i}=t;switch(t.layout){case m.simple:return e("div",{className:"flex flex-col space-y-1 rounded-md p-2 shadow-sm",children:i});case m.grid:return e("div",{className:"grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3",children:i});case m.card:return e("div",{className:"grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3",children:i});default:return i}};function z(){const[t,i]=g(l);return{listQuery:t}}export{_ as CommonListView,K as CommonListViewProvider,z as useCommonListView};
1
+ "use client";import{Fragment as k,jsx as e,jsxs as p}from"react/jsx-runtime";import{useSuspenseInfiniteQuery as f}from"gomtm/connectquery";import{ListViewLayout as m}from"gomtm/gomtmpb/mtm/sppb/mtm_pb";import{atom as y,useAtom as g}from"jotai";import{useHydrateAtoms as c}from"jotai/utils";import{ListItemView as P}from"../components/ListItem";import{MtUnaryCallErrorView as L}from"../components/MtUnaryCallErrorView";import{cn as h}from"../lib/utils";import{Pagination as I,PaginationContent as v,PaginationEllipsis as w,PaginationItem as r,PaginationLink as u,PaginationNext as x,PaginationPrevious as M}from"../ui/pagination";const l=y(null);function H(t){const{children:i,methodList:n}=t,o=f(n,{page:1},{pageParamKey:"pagination",getNextPageParam:(a,d,s)=>({page:((s==null?void 0:s.page)||0)+1})});return c([[l,o]]),e(k,{children:i})}function K(){const[t,i]=g(l);return t!=null&&t.data?p("div",{className:"relative w-full",children:[e("div",{className:h("w-full"),children:t.data.pages.map((n,o)=>{var a;return n.error_code?e(L,{unaryError:n},o):e(C,{layout:n.listLayout,children:(a=n==null?void 0:n.items)==null?void 0:a.map((d,s)=>e(P,{item:d},`${o}-${s}`))},o)})}),e(I,{children:p(v,{children:[e(r,{children:e(M,{href:"#"})}),e(r,{children:e(u,{href:"#",children:"1"})}),e(r,{children:e(u,{href:"#",isActive:!0,children:"2"})}),e(r,{children:e(u,{href:"#",children:"3"})}),e(r,{children:e(w,{})}),e(r,{children:e(x,{href:"#"})})]})}),e("div",{className:"absolute right-1 top-1"})]}):null}const C=t=>{const{children:i}=t;switch(t.layout){case m.simple:return e("div",{className:"flex flex-col space-y-1 rounded-md p-2 shadow-sm",children:i});case m.grid:return e("div",{className:"grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3",children:i});case m.card:return e("div",{className:"grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3",children:i});default:return i}};function _(){const[t,i]=g(l);return{listQuery:t}}export{K as CommonListView,H as CommonListViewProvider,_ as useCommonListView};
@@ -1,6 +1,5 @@
1
1
  import { PlainMessage } from "gomtm";
2
- import { MtUnaryCallError } from "gomtm/connectquery/utils";
3
- import { CommontListRes, CurdView } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
2
+ import { CurdView } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
4
3
  import { PropsWithChildren } from "react";
5
4
  export declare const activateIdAtom: import("jotai").PrimitiveAtom<string> & {
6
5
  init: string;
@@ -75,8 +74,3 @@ export declare function useCurdView(): {
75
74
  createLink: string;
76
75
  showLink: (id: string) => string;
77
76
  };
78
- export declare function useCurdViewList<T = CommontListRes & MtUnaryCallError, E = any>(): {
79
- query: import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<T, unknown>, E>;
80
- loadedCount: number;
81
- canLoadMore: boolean;
82
- };
@@ -1 +1 @@
1
- "use client";var d=(a,e,n)=>new Promise((u,p)=>{var s=r=>{try{i(n.next(r))}catch(t){p(t)}},c=r=>{try{i(n.throw(r))}catch(t){p(t)}},i=r=>r.done?u(r.value):Promise.resolve(r.value).then(s,c);i((n=n.apply(a,e)).next())});import{jsx as J}from"react/jsx-runtime";import{useQueryClient as Q,useSuspenseInfiniteQuery as I}from"@tanstack/react-query";import{toPlainMessage as R}from"gomtm";import{useSuspenseQuery as U}from"gomtm/connectquery";import{curdViewGet as K}from"gomtm/gomtmpb/mtm/sppb/mtm-MtmService_connectquery";import{mtmCallUnaryMethod as G}from"gomtm/mtmFetcher";import{createInfiniteQueryKey as O,createQueryKey as T}from"gomtm/mtmquery";import{useExtInfo as b}from"gomtm/providers/GomtmProvider";import{useIsAdmin as z}from"gomtm/providers/userContext";import{Provider as W,atom as C,createStore as D,useAtom as P}from"jotai";import{usePathname as F}from"next/navigation";import{compile as g,match as v}from"path-to-regexp";import{useCallback as f,useMemo as m}from"react";import{useMtRouter as j}from"../hooks/use-router";const B=C("0"),H=C(null),S=C(""),y=D(),ht=a=>{const{idOrName:e,children:n}=a;return m(()=>{y.set(S,e)},[e]),J(W,{store:y,children:n})};function dt(){const a=F(),[e,n]=P(B,{store:y}),[u,p]=P(S,{store:y}),s=z(),c=j(),i=Q(),r=U(K,{id:u}),t=m(()=>{var o,h;return(h=(o=r.data)==null?void 0:o.item)==null?void 0:h.value},[r.data]),E=m(()=>s,[s]),L=m(()=>s,[s]),x=m(()=>s,[s]),l=f(o=>t!=null&&t.routeShow?g(t==null?void 0:t.routeShow,{encode:encodeURIComponent})({id:o}):"",[t==null?void 0:t.routeShow]),M=f(o=>{l&&c.push(l(o))},[c,l]),N=f(()=>d(this,null,function*(){t&&(yield i.invalidateQueries({queryKey:O(t.svcName,t.methodList)}))}),[t,i]),k=f(()=>d(this,null,function*(){t&&(yield i.invalidateQueries({queryKey:T(t.svcName,t.methodGet)}))}),[t,i]),q=f(o=>t!=null&&t.routeEdit?g(t==null?void 0:t.routeEdit,{encode:encodeURIComponent})({id:o}):"",[t==null?void 0:t.routeEdit]),A=m(()=>t!=null&&t.routeCreate?g(t==null?void 0:t.routeCreate,{encode:encodeURIComponent})({id:e}):"",[t==null?void 0:t.routeCreate,e]);return m(()=>{if(t!=null&&t.routeShow){const o=v(t.routeShow)(a);o&&n(o.params.id)}else if(t!=null&&t.routeEdit){const o=v(t.routeShow)(a);o&&n(o.params.id)}},[t==null?void 0:t.routeEdit,t==null?void 0:t.routeShow,a,n]),{curdView:t,canEdit:E,canCreate:L,canDelete:x,openShow:M,invalidateList:N,invalidateGet:k,activateId:e,setActivateId:n,editLink:q,createLink:A,showLink:l}}function yt(){const a=b(),[e,n]=P(H),u=I({queryKey:[e==null?void 0:e.svcName,e==null?void 0:e.methodList],queryFn:i=>d(this,null,function*(){const r=yield G(a,(e==null?void 0:e.svcName)||"",(e==null?void 0:e.methodList)||"");return R(r)}),initialPageParam:{},getNextPageParam:()=>{}}),p=(e==null?void 0:e.pageSize)||12,s=m(()=>u.data?u.data.pages.length*p:0,[p,u.data]),c=m(()=>!0,[]);return{query:u,loadedCount:s,canLoadMore:c}}export{ht as CurdViewView,B as activateIdAtom,y as curdStore,H as curdViewAtom,S as curdViewIdAtom,dt as useCurdView,yt as useCurdViewList};
1
+ "use client";var C=(a,m,o)=>new Promise((f,l)=>{var n=r=>{try{s(o.next(r))}catch(t){l(t)}},c=r=>{try{s(o.throw(r))}catch(t){l(t)}},s=r=>r.done?f(r.value):Promise.resolve(r.value).then(n,c);s((o=o.apply(a,m)).next())});import{jsx as w}from"react/jsx-runtime";import{useQueryClient as q}from"@tanstack/react-query";import{useSuspenseQuery as K}from"gomtm/connectquery";import{curdViewGet as M}from"gomtm/gomtmpb/mtm/sppb/mtm-MtmService_connectquery";import{createInfiniteQueryKey as G,createQueryKey as O}from"gomtm/mtmquery";import{useIsAdmin as R}from"gomtm/providers/userContext";import{Provider as b,atom as y,createStore as U,useAtom as v}from"jotai";import{usePathname as W}from"next/navigation";import{compile as P,match as S}from"path-to-regexp";import{useCallback as u,useMemo as i}from"react";import{useMtRouter as D}from"../hooks/use-router";const j=y("0"),nt=y(null),I=y(""),h=U(),st=a=>{const{idOrName:m,children:o}=a;return i(()=>{h.set(I,m)},[m]),w(b,{store:h,children:o})};function at(){const a=W(),[m,o]=v(j,{store:h}),[f,l]=v(I,{store:h}),n=R(),c=D(),s=q(),r=K(M,{id:f}),t=i(()=>{var e,d;return(d=(e=r.data)==null?void 0:e.item)==null?void 0:d.value},[r.data]),A=i(()=>n,[n]),E=i(()=>n,[n]),g=i(()=>n,[n]),p=u(e=>t!=null&&t.routeShow?P(t==null?void 0:t.routeShow,{encode:encodeURIComponent})({id:e}):"",[t==null?void 0:t.routeShow]),k=u(e=>{p&&c.push(p(e))},[c,p]),Q=u(()=>C(this,null,function*(){t&&(yield s.invalidateQueries({queryKey:G(t.svcName,t.methodList)}))}),[t,s]),x=u(()=>C(this,null,function*(){t&&(yield s.invalidateQueries({queryKey:O(t.svcName,t.methodGet)}))}),[t,s]),L=u(e=>t!=null&&t.routeEdit?P(t==null?void 0:t.routeEdit,{encode:encodeURIComponent})({id:e}):"",[t==null?void 0:t.routeEdit]),N=i(()=>t!=null&&t.routeCreate&&(t==null?void 0:t.routeCreate)||"",[t==null?void 0:t.routeCreate]);return i(()=>{if(t!=null&&t.routeShow){const e=S(t.routeShow)(a);e&&o(e.params.id)}else if(t!=null&&t.routeEdit){const e=S(t.routeShow)(a);e&&o(e.params.id)}},[t==null?void 0:t.routeEdit,t==null?void 0:t.routeShow,a,o]),{curdView:t,canEdit:A,canCreate:E,canDelete:g,openShow:k,invalidateList:Q,invalidateGet:x,activateId:m,setActivateId:o,editLink:L,createLink:N,showLink:p}}export{st as CurdViewView,j as activateIdAtom,h as curdStore,nt as curdViewAtom,I as curdViewIdAtom,at as useCurdView};
@@ -1 +1 @@
1
- "use client";var c=(d,a,o)=>new Promise((n,r)=>{var i=e=>{try{t(o.next(e))}catch(s){r(s)}},l=e=>{try{t(o.throw(e))}catch(s){r(s)}},t=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,l);t((o=o.apply(d,a)).next())});import{Fragment as g,jsx as m,jsxs as u}from"react/jsx-runtime";import{useSuspenseQuery as y}from"@tanstack/react-query";import{MtUnaryCallErrorView as E}from"../../components/MtUnaryCallErrorView";import{fakeFetchUser as p}from"./lib";const f=(d,a)=>c(void 0,null,function*(){try{return{code:"",data:yield p(d,!a)}}catch(o){return{error_code:"some_error_code",error_message:"error message"}}});function _(d){var i,l,t,e,s;const{userId:a,randomError:o,isHardError:n}=d,r=y({queryKey:["userId",a],queryFn:()=>c(this,null,function*(){if(n)throw console.log("isHardError",n),new Error("isHardError=true");return f(a,o)})});return r.error?u("div",{children:["query error:",JSON.stringify(r.error)]}):u("div",{className:"border-spacing-1 border p-2",children:[u("div",{className:"bg-slate-200",children:["userId:",a,",randomError:",o,",isHardError:",n]}),r.data&&((i=r.data)!=null&&i.error_code)?m(g,{children:m(E,{unaryError:r.data})}):u("pre",{children:[(t=(l=r.data)==null?void 0:l.data)==null?void 0:t.id,",",JSON.stringify((s=(e=r.data)==null?void 0:e.data)==null?void 0:s.id,null,2)]})]})}export{_ as DemoUserDetail};
1
+ "use client";var c=(i,a,o)=>new Promise((d,r)=>{var n=e=>{try{s(o.next(e))}catch(t){r(t)}},m=e=>{try{s(o.throw(e))}catch(t){r(t)}},s=e=>e.done?d(e.value):Promise.resolve(e.value).then(n,m);s((o=o.apply(i,a)).next())});import{Fragment as g,jsx as l,jsxs as u}from"react/jsx-runtime";import{useSuspenseQuery as y}from"@tanstack/react-query";import{MtUnaryCallErrorView as E}from"../../components/MtUnaryCallErrorView";import{fakeFetchUser as p}from"./lib";const f=(i,a)=>c(void 0,null,function*(){try{return{code:"",data:yield p(i,!a)}}catch(o){return{error_code:"some_error_code",error_message:"error message"}}});function I(i){var n,m,s,e,t;const{userId:a,randomError:o,isHardError:d}=i,r=y({queryKey:["userId",a],queryFn:()=>c(this,null,function*(){if(d)throw console.log("isHardError",d),new Error("isHardError=true");return f(a,o)})});return r.error?u("div",{children:["query error:",JSON.stringify(r.error)]}):u("div",{className:"border-spacing-1 border p-2",children:[u("div",{className:"bg-slate-200",children:["userId:",a,",randomError:",o,",isHardError:",d]}),r.data&&((n=r.data)!=null&&n.error_code)?l(g,{children:l(E,{unaryError:r.data})}):u("pre",{children:[(s=(m=r.data)==null?void 0:m.data)==null?void 0:s.id,",",JSON.stringify((t=(e=r.data)==null?void 0:e.data)==null?void 0:t.id,null,2)]})]})}export{I as DemoUserDetail};
@@ -1 +1 @@
1
- "use client";var G=Object.defineProperty,J=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var v=(n,t,o)=>t in n?G(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,d=(n,t)=>{for(var o in t||(t={}))L.call(t,o)&&v(n,o,t[o]);if(H)for(var o of H(t))Q.call(t,o)&&v(n,o,t[o]);return n},c=(n,t)=>J(n,K(t));import{jsx as e,jsxs as i}from"react/jsx-runtime";import{atom as D,useAtom as a,useSetAtom as f}from"jotai";import{useCallback as M}from"react";import{FormProvider as F,useForm as O}from"react-hook-form";import{useIsDesktop as y}from"../hooks/use-media-query";import{Dialog as x,DialogContent as S,DialogDescription as A,DialogFooter as U,DialogHeader as I,DialogTitle as T}from"../ui/dialog";import{Drawer as h,DrawerClose as W,DrawerContent as k,DrawerDescription as N,DrawerFooter as X,DrawerHeader as R,DrawerTitle as V}from"../ui/drawer";import{MtButton as B}from"../ui/ui-mt/Button";import{EditFormToolbar as Y}from"./EditFormToolbar";import{SchemaFormFieldsRender as E}from"./SchemaFormViewV2";const g=D(!1),w=D({}),C=D(null),P=D(null),q=D(null),Fo=()=>{const n=f(w),t=f(C),o=f(P),r=f(g),s=f(q),m=M((u,l,b)=>{console.log("openPopform",u,l),o(()=>b),n(l),t(u),r(!0)},[n,t,o,r]),p=M(u=>{s(()=>u),r(!0)},[r,s]);return{openSchemaForm:m,setOpen:r,openComponent:p}};function go(){const[n,t]=a(g);if(n)return e(Z,{})}function Z(){const n=y(),[t]=a(w),[o]=a(C),[r]=a(P),[s,m]=a(g),[p,u]=a(q),l=O({defaultValues:t}),b=z=>{r&&r(z)};return s&&p?e(_,{}):n?e(x,{open:s,onOpenChange:m,children:i(S,{className:"sm:max-w-[425px]",children:[i(I,{children:[e(T,{children:o==null?void 0:o.title}),e(A,{children:o==null?void 0:o.description})]}),e(F,c(d({},l),{children:i("form",{onSubmit:l.handleSubmit(b),children:[e(E,{schema:o}),e(U,{children:e(Y,{onCancel:()=>m(!1)})})]})}))]})}):e(h,{open:s,onOpenChange:m,children:e(k,{children:i("div",{className:"mx-auto w-full max-w-sm",children:[i(R,{children:[e(V,{children:o==null?void 0:o.title}),e(N,{children:o==null?void 0:o.description})]}),e(F,c(d({},l),{children:i("form",{onSubmit:l.handleSubmit(b),children:[e(E,{schema:o}),i(X,{children:[e(B,{type:"submit",children:"Submit"}),e(W,{asChild:!0,children:e(B,{variant:"outline",children:"Cancel"})})]})]})}))]})})})}function _(){const n=y(),[t]=a(w),[o]=a(C),[r]=a(P),[s,m]=a(g),p=O({defaultValues:t}),u=l=>{r&&r(l)};return n?e(x,{open:s,onOpenChange:m,children:i(S,{className:"sm:max-w-[425px]",children:[i(I,{children:[e(T,{children:o==null?void 0:o.title}),e(A,{children:o==null?void 0:o.description})]}),e(F,c(d({},p),{children:e("form",{onSubmit:p.handleSubmit(u),children:"component todo"})}))]})}):e(h,{open:s,onOpenChange:m,children:e(k,{children:i("div",{className:"mx-auto w-full max-w-sm",children:[i(R,{children:[e(V,{children:o==null?void 0:o.title}),e(N,{children:o==null?void 0:o.description})]}),e(F,c(d({},p),{children:e("form",{onSubmit:p.handleSubmit(u),children:"component todo"})}))]})})})}export{go as MtFormPopupHolder,Fo as usePopupForm};
1
+ "use client";var G=Object.defineProperty,J=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable;var v=(n,t,o)=>t in n?G(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,d=(n,t)=>{for(var o in t||(t={}))L.call(t,o)&&v(n,o,t[o]);if(H)for(var o of H(t))Q.call(t,o)&&v(n,o,t[o]);return n},c=(n,t)=>J(n,K(t));import{jsx as e,jsxs as i}from"react/jsx-runtime";import{atom as D,useAtom as a,useSetAtom as f}from"jotai";import{useCallback as M}from"react";import{FormProvider as F,useForm as O}from"react-hook-form";import{useIsDesktop as y}from"../hooks/use-media-query";import{Dialog as x,DialogContent as S,DialogDescription as A,DialogFooter as U,DialogHeader as I,DialogTitle as T}from"../ui/dialog";import{Drawer as h,DrawerClose as W,DrawerContent as k,DrawerDescription as N,DrawerFooter as X,DrawerHeader as R,DrawerTitle as V}from"../ui/drawer";import{MtButton as B}from"../ui/ui-mt/Button";import{EditFormToolbar as Y}from"./EditFormToolbar";import{SchemaFormFieldsRender as E}from"./formFieldRender/SchemaFormFieldsRender";const g=D(!1),w=D({}),C=D(null),P=D(null),q=D(null),Fo=()=>{const n=f(w),t=f(C),o=f(P),r=f(g),s=f(q),m=M((u,l,b)=>{console.log("openPopform",u,l),o(()=>b),n(l),t(u),r(!0)},[n,t,o,r]),p=M(u=>{s(()=>u),r(!0)},[r,s]);return{openSchemaForm:m,setOpen:r,openComponent:p}};function go(){const[n,t]=a(g);if(n)return e(Z,{})}function Z(){const n=y(),[t]=a(w),[o]=a(C),[r]=a(P),[s,m]=a(g),[p,u]=a(q),l=O({defaultValues:t}),b=z=>{r&&r(z)};return s&&p?e(_,{}):n?e(x,{open:s,onOpenChange:m,children:i(S,{className:"sm:max-w-[425px]",children:[i(I,{children:[e(T,{children:o==null?void 0:o.title}),e(A,{children:o==null?void 0:o.description})]}),e(F,c(d({},l),{children:i("form",{onSubmit:l.handleSubmit(b),children:[e(E,{schema:o}),e(U,{children:e(Y,{onCancel:()=>m(!1)})})]})}))]})}):e(h,{open:s,onOpenChange:m,children:e(k,{children:i("div",{className:"mx-auto w-full max-w-sm",children:[i(R,{children:[e(V,{children:o==null?void 0:o.title}),e(N,{children:o==null?void 0:o.description})]}),e(F,c(d({},l),{children:i("form",{onSubmit:l.handleSubmit(b),children:[e(E,{schema:o}),i(X,{children:[e(B,{type:"submit",children:"Submit"}),e(W,{asChild:!0,children:e(B,{variant:"outline",children:"Cancel"})})]})]})}))]})})})}function _(){const n=y(),[t]=a(w),[o]=a(C),[r]=a(P),[s,m]=a(g),p=O({defaultValues:t}),u=l=>{r&&r(l)};return n?e(x,{open:s,onOpenChange:m,children:i(S,{className:"sm:max-w-[425px]",children:[i(I,{children:[e(T,{children:o==null?void 0:o.title}),e(A,{children:o==null?void 0:o.description})]}),e(F,c(d({},p),{children:e("form",{onSubmit:p.handleSubmit(u),children:"component todo"})}))]})}):e(h,{open:s,onOpenChange:m,children:e(k,{children:i("div",{className:"mx-auto w-full max-w-sm",children:[i(R,{children:[e(V,{children:o==null?void 0:o.title}),e(N,{children:o==null?void 0:o.description})]}),e(F,c(d({},p),{children:e("form",{onSubmit:p.handleSubmit(u),children:"component todo"})}))]})})})}export{go as MtFormPopupHolder,Fo as usePopupForm};
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "@bufbuild/protobuf";
3
+ import { FormSchema } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
4
+ import { MaybePromise } from "../types/common";
5
+ type SchemaFormViewVaranit = "auto" | "modal" | "card";
6
+ export declare const SchemaFormView: (props: {
7
+ formSchema?: PlainMessage<FormSchema> | undefined;
8
+ defaultValues?: any;
9
+ onSubmit: (values: any) => MaybePromise<void>;
10
+ onCancel?: (() => void) | undefined;
11
+ isLoading?: boolean | undefined;
12
+ variants?: SchemaFormViewVaranit | undefined;
13
+ }) => import("react").JSX.Element;
14
+ export {};
@@ -0,0 +1 @@
1
+ "use client";var d=Object.defineProperty,f=Object.defineProperties;var u=Object.getOwnPropertyDescriptors;var i=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,F=Object.prototype.propertyIsEnumerable;var t=(a,o,r)=>o in a?d(a,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[o]=r,n=(a,o)=>{for(var r in o||(o={}))p.call(o,r)&&t(a,r,o[r]);if(i)for(var r of i(o))F.call(o,r)&&t(a,r,o[r]);return a},s=(a,o)=>f(a,u(o));import{Fragment as M,jsx as e,jsxs as P}from"react/jsx-runtime";import{useState as S}from"react";import{FormProvider as h,useForm as v}from"react-hook-form";import{Card as C,CardContent as V}from"../ui/card";import{DialogFooter as b}from"../ui/dialog";import{EditFormToolbar as g}from"./EditFormToolbar";import{SchemaFormFieldsRender as y}from"./formFieldRender/SchemaFormFieldsRender";const I=a=>{const{formSchema:o,onSubmit:r,onCancel:m,variants:w}=a,[l,D]=S({}),c=v({defaultValues:l});return o?e(M,{children:e(h,s(n({},c),{children:e(C,{className:"p-2",children:e(V,{children:P("form",{onSubmit:r,children:[e(y,{schema:o}),e(b,{children:e(g,{onCancel:()=>m&&m()})})]})})})}))}):e("div",{className:"border p-8",children:"missing formSchema params"})};export{I as SchemaFormView};
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "gomtm";
3
+ import { FormSchema } from "gomtm/gomtmpb/mtm/sppb/mtm_pb";
4
+ export declare const SchemaFormFieldsRender: (props: {
5
+ schema: PlainMessage<FormSchema>;
6
+ }) => import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ "use client";var F=Object.defineProperty;var n=Object.getOwnPropertySymbols;var u=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable;var l=(r,e,o)=>e in r?F(r,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):r[e]=o,s=(r,e)=>{for(var o in e||(e={}))u.call(e,o)&&l(r,o,e[o]);if(n)for(var o of n(e))h.call(e,o)&&l(r,o,e[o]);return r};import{Fragment as c,jsx as m,jsxs as D}from"react/jsx-runtime";import{useFormContext as d}from"react-hook-form";import{FormField as b,FormItem as f,FormLabel as g,FormControl as C,FormDescription as I,FormMessage as M}from"../../ui/form";import{Input as S}from"../../ui/input";const v=r=>{var a;const{schema:e}=r,o=d();return m(c,{children:(a=e.fields)==null?void 0:a.map((t,p)=>m(b,{control:o.control,name:t.name,defaultValue:t.defaultValue||"",render:({field:i})=>D(f,{children:[t.label&&m(g,{children:t.label}),m(C,{children:m(c,{children:m(S,s({placeholder:t.placeholder},i))})}),t.description&&m(I,{children:t.description}),m(M,{})]})},p))})};export{v as SchemaFormFieldsRender};