mtxuilib 0.0.404 → 0.0.405

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};