gomtm 0.0.322 → 0.0.324

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.
@@ -0,0 +1,18 @@
1
+ import { PlainMessage } from "@bufbuild/protobuf";
2
+ import { PropsWithChildren } from "react";
3
+ import { CommonListItem, ListItem, ListViewLayout, PostCardItem } from "../../gomtmpb/mtm/sppb/mtm_pb";
4
+ export declare const ListViewLayoutRender: (props: {
5
+ layout: ListViewLayout;
6
+ } & PropsWithChildren) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<import("react").AwaitedReactNode> | import("react").JSX.Element | null | undefined;
7
+ export declare const ListItemView: (props: {
8
+ item: PlainMessage<ListItem>;
9
+ }) => import("react").JSX.Element | null;
10
+ export declare const CommonListItemView: (props: {
11
+ item: PlainMessage<CommonListItem>;
12
+ }) => import("react").JSX.Element;
13
+ export declare const PostCardListItem: (props: {
14
+ item: PostCardItem;
15
+ }) => import("react").JSX.Element;
16
+ export declare const PostCardItemActions: (props: {
17
+ id: string;
18
+ }) => import("react").JSX.Element;
@@ -0,0 +1,213 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { MtLink } from "mtxuilib/common/mtlink";
4
+ import { Icons } from "mtxuilib/icons/icons";
5
+ import { cn } from "mtxuilib/lib/utils";
6
+ import { buttonVariants } from "mtxuilib/ui/button";
7
+ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "mtxuilib/ui/card";
8
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
9
+ import { title } from "process";
10
+ import { useState } from "react";
11
+ import { MtDateView } from "../../components/MtDate";
12
+ import Tag from "../../components/Tag";
13
+ import { ListViewLayout } from "../../gomtmpb/mtm/sppb/mtm_pb";
14
+ import { useListview } from "../listview/list-store";
15
+ const ListViewLayoutRender = (props) => {
16
+ const { children } = props;
17
+ switch (props.layout) {
18
+ case ListViewLayout.simple:
19
+ return /* @__PURE__ */ jsx("ul", { className: "divide-y divide-gray-200 dark:divide-gray-700", children });
20
+ case ListViewLayout.grid:
21
+ return /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3", children });
22
+ case ListViewLayout.card:
23
+ return /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3", children });
24
+ default:
25
+ return children;
26
+ }
27
+ };
28
+ const ListItemView = (props) => {
29
+ var _a, _b;
30
+ const { item } = props;
31
+ if ((_a = item == null ? void 0 : item.item) == null ? void 0 : _a.value) {
32
+ const itemCase = ((_b = item.item) == null ? void 0 : _b.case) || "";
33
+ switch (itemCase) {
34
+ case "commonListItem":
35
+ return /* @__PURE__ */ jsx(CommonListItemView, { item: item.item.value });
36
+ case "postCard":
37
+ return /* @__PURE__ */ jsx(PostCardListItem, { item: item.item.value });
38
+ default:
39
+ return /* @__PURE__ */ jsx("span", { className: "bg-red-600 p-2", children: "unknow list item type" });
40
+ }
41
+ }
42
+ return null;
43
+ };
44
+ const CommonListItemView = (props) => {
45
+ const { item } = props;
46
+ const handleSelect = () => {
47
+ };
48
+ const slugPath = useListview((x) => x.slugPath);
49
+ return /* @__PURE__ */ jsxs(
50
+ "div",
51
+ {
52
+ "aria-label": item.id,
53
+ onClick: handleSelect,
54
+ className: cn(
55
+ buttonVariants({
56
+ variant: "ghost"
57
+ }),
58
+ "flex min-h-16 justify-start border p-4 text-left"
59
+ ),
60
+ children: [
61
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxs(MtLink, { href: `${slugPath}/${item.id}`, children: [
62
+ slugPath,
63
+ item.title || item.id,
64
+ item.description && /* @__PURE__ */ jsx("div", { children: item.description })
65
+ ] }) }),
66
+ /* @__PURE__ */ jsx(PostCardItemActions, { id: item.id })
67
+ ]
68
+ }
69
+ );
70
+ };
71
+ const PostCardListItem = (props) => {
72
+ const { item } = props;
73
+ const slugPath = useListview((x) => x.slugPath);
74
+ const activateItem = useListview((x) => x.activateItem);
75
+ const setActivateItem = useListview((x) => x.setActivateItem);
76
+ if (item.layoutVariant == "list") {
77
+ return /* @__PURE__ */ jsx("li", { className: "py-12", children: /* @__PURE__ */ jsx("article", { children: /* @__PURE__ */ jsxs("div", { className: "space-y-2 xl:grid xl:grid-cols-4 xl:items-baseline xl:space-y-0", children: [
78
+ /* @__PURE__ */ jsxs("dl", { children: [
79
+ /* @__PURE__ */ jsx("dt", { className: "sr-only", children: "Published on" }),
80
+ /* @__PURE__ */ jsx("dd", { className: "text-base font-medium leading-6 text-gray-500 dark:text-gray-400", children: /* @__PURE__ */ jsx(MtDateView, { date: item.publishDate }) })
81
+ ] }),
82
+ /* @__PURE__ */ jsxs("div", { className: "space-y-5 xl:col-span-3", children: [
83
+ /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
84
+ /* @__PURE__ */ jsxs("div", { children: [
85
+ /* @__PURE__ */ jsx("h2", { className: "text-2xl font-bold leading-8 tracking-tight", children: /* @__PURE__ */ jsx(
86
+ MtLink,
87
+ {
88
+ href: `/blog/${item.slug}`,
89
+ className: "text-gray-900 dark:text-gray-100",
90
+ children: item.title
91
+ }
92
+ ) }),
93
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap", children: item.tags.map((tag) => /* @__PURE__ */ jsx(Tag, { text: tag }, tag)) })
94
+ ] }),
95
+ /* @__PURE__ */ jsx("div", { className: "prose max-w-none text-gray-500 dark:text-gray-400", children: item.summary })
96
+ ] }),
97
+ /* @__PURE__ */ jsx("div", { className: "text-base font-medium leading-6", children: /* @__PURE__ */ jsx(
98
+ MtLink,
99
+ {
100
+ href: `/blog/${item.slug}`,
101
+ className: "text-primary-500 hover:text-primary-600 dark:hover:text-primary-400",
102
+ "aria-label": `Read more: "${title}"`,
103
+ children: "Read more \u2192"
104
+ }
105
+ ) })
106
+ ] })
107
+ ] }) }) });
108
+ }
109
+ return /* @__PURE__ */ jsxs(
110
+ Card,
111
+ {
112
+ className: cn(
113
+ "m-2 w-[350px]",
114
+ item.id == (activateItem == null ? void 0 : activateItem.id) && " p-2 shadow-md"
115
+ ),
116
+ onClick: () => {
117
+ setActivateItem(item);
118
+ },
119
+ children: [
120
+ /* @__PURE__ */ jsxs(CardHeader, { children: [
121
+ /* @__PURE__ */ jsx(CardTitle, { children: /* @__PURE__ */ jsx(MtLink, { href: `${slugPath}/${item.id}`, className: "pb-4 text-3xl font-bold hover:text-gray-700", children: item == null ? void 0 : item.title }) }),
122
+ /* @__PURE__ */ jsx(CardDescription, { children: "Deploy your new project in one-click." })
123
+ ] }),
124
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("article", { className: "my-4 flex flex-col", children: [
125
+ /* @__PURE__ */ jsx(MtLink, {
126
+ href: `${slugPath}/${item.id}`,
127
+ className: "hover:opacity-75",
128
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
129
+ children: item.topImage && /* @__PURE__ */ jsx("img", { src: item.topImage, alt: item.title })
130
+ }),
131
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-start bg-white p-6", children: [
132
+ /* @__PURE__ */ jsx(MtLink, { href: `${slugPath}/${item.id}`, className: "pb-4 text-sm font-bold uppercase text-blue-700", children: item.category || "news" }),
133
+ /* @__PURE__ */ jsxs("p", { className: "pb-3 text-sm", children: [
134
+ "By ",
135
+ /* @__PURE__ */ jsx(MtLink, { href: "#", children: item.author }),
136
+ ","
137
+ ] }),
138
+ /* @__PURE__ */ jsx("div", { children: item.excerpt })
139
+ ] })
140
+ ] }) }),
141
+ /* @__PURE__ */ jsxs(CardFooter, { className: "flex justify-end", children: [
142
+ /* @__PURE__ */ jsx(MtLink, { variant: "ghost", href: `${slugPath}/${item.id}`, children: "Show" }),
143
+ /* @__PURE__ */ jsx(PostCardItemActions, { id: item.id })
144
+ ] })
145
+ ]
146
+ }
147
+ );
148
+ };
149
+ const PostCardItemActions = (props) => {
150
+ const { id } = props;
151
+ const setOpenCreate = useListview((x) => x.setOpenCreate);
152
+ const setOpenRemove = useListview((x) => x.setOpenRemove);
153
+ const slugPath = useListview((x) => x.slugPath);
154
+ const [open, setOpen] = useState(false);
155
+ const setOpenEdit = useListview((x) => x.setOpenEdit);
156
+ return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, children: [
157
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
158
+ MtLink,
159
+ {
160
+ href: `${slugPath}/${id}`,
161
+ variant: "ghost",
162
+ className: "data-[state=open]:bg-muted flex size-8 p-0",
163
+ children: [
164
+ /* @__PURE__ */ jsx(Icons.chevronRight, { className: "size-4" }),
165
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "more" })
166
+ ]
167
+ }
168
+ ) }),
169
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-[160px]", children: [
170
+ /* @__PURE__ */ jsx(
171
+ DropdownMenuItem,
172
+ {
173
+ onClick: (e) => {
174
+ e.preventDefault();
175
+ setOpenCreate(true);
176
+ setOpen(false);
177
+ },
178
+ children: "create"
179
+ }
180
+ ),
181
+ /* @__PURE__ */ jsx(
182
+ DropdownMenuItem,
183
+ {
184
+ onClick: (e) => {
185
+ e.preventDefault();
186
+ setOpenEdit(true);
187
+ setOpen(false);
188
+ },
189
+ children: "edit"
190
+ }
191
+ ),
192
+ /* @__PURE__ */ jsx(
193
+ DropdownMenuItem,
194
+ {
195
+ onClick: (e) => {
196
+ e.preventDefault();
197
+ setOpenRemove(true);
198
+ setOpen(false);
199
+ },
200
+ children: "remove"
201
+ }
202
+ ),
203
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
204
+ ] })
205
+ ] });
206
+ };
207
+ export {
208
+ CommonListItemView,
209
+ ListItemView,
210
+ ListViewLayoutRender,
211
+ PostCardItemActions,
212
+ PostCardListItem
213
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export declare const LzListViewLayoutDemo: import("react").LazyExoticComponent<typeof import("./listview-layouts/listviewlayout-demo").default>;
3
+ export declare const LzListViewLayoutDefault: import("react").LazyExoticComponent<typeof import("./listview-layouts/default").default>;
4
+ export declare function CommonListView(): import("react").JSX.Element | null;
5
+ export declare const ListViewActions: () => import("react").JSX.Element;
@@ -0,0 +1,114 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { Icons } from "mtxuilib/icons/icons";
4
+ import { cn } from "mtxuilib/lib/utils";
5
+ import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
6
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
7
+ import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
8
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
9
+ import { Suspense, lazy, useMemo, useState } from "react";
10
+ import { useHotkeys } from "react-hotkeys-hook";
11
+ import { MtmErrorView } from "../../components/MtmErrorView";
12
+ import { HOTKEY_Listview_Switchlayout } from "../../consts";
13
+ import { useGomtmSuspenseInfiniteQuery } from "../../gomtmQuery";
14
+ import { CurdCreatePanelTriggerButton } from "../create/CurdCreatePanel";
15
+ import { CurdEditPanelTriggerButton } from "../edit/CurdEditPanel";
16
+ import { ListItemView, ListViewLayoutRender } from "../list-item/ListViewLayoutRender";
17
+ import { useListview } from "./list-store";
18
+ const ALL_Layouts = [
19
+ "default",
20
+ "demo"
21
+ ];
22
+ const LzListViewLayoutDemo = lazy(() => import("./listview-layouts/listviewlayout-demo"));
23
+ const LzListViewLayoutDefault = lazy(() => import("./listview-layouts/default"));
24
+ function CommonListView() {
25
+ const svc = useListview((x) => x.svc);
26
+ const methodList = useListview((x) => x.methodList);
27
+ const paramList = useListview((x) => x.paramsList);
28
+ const listQuery = useGomtmSuspenseInfiniteQuery(svc, methodList, paramList);
29
+ if (!(listQuery == null ? void 0 : listQuery.data)) {
30
+ return null;
31
+ }
32
+ return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
33
+ /* @__PURE__ */ jsx(
34
+ "div",
35
+ {
36
+ className: cn(
37
+ "w-full"
38
+ // 滚动设置
39
+ // " max-h-[700px] overflow-y-auto"
40
+ ),
41
+ children: listQuery.data.pages.map((page, i) => {
42
+ var _a;
43
+ if (page.errCode) {
44
+ return /* @__PURE__ */ jsx(MtmErrorView, { unaryError: page }, i);
45
+ } else {
46
+ return /* @__PURE__ */ jsx(ListViewLayoutRender, { layout: page.listLayout, children: (_a = page == null ? void 0 : page.items) == null ? void 0 : _a.map((item, j) => /* @__PURE__ */ jsx(ListItemView, { item }, `${i}-${j}`)) }, i);
47
+ }
48
+ })
49
+ }
50
+ ),
51
+ listQuery.data.pages && !!listQuery.data.pages.length && /* @__PURE__ */ jsx(Pagination, { children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
52
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, { href: "#" }) }),
53
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "1" }) }),
54
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", isActive: true, children: "2" }) }),
55
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "3" }) }),
56
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
57
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
58
+ ] }) }),
59
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1", children: /* @__PURE__ */ jsx(ListViewActions, {}) })
60
+ ] });
61
+ }
62
+ const ListViewActions = () => {
63
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
64
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { variant: "ghost", className: "m-0 flex h-10 w-10 items-center justify-center border p-0 shadow-sm backdrop-blur", children: /* @__PURE__ */ jsx(Icons.ellipsis, {}) }) }),
65
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { className: "w-56", children: [
66
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Edit" }),
67
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
68
+ /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 p-2", children: [
69
+ /* @__PURE__ */ jsx(CurdEditPanelTriggerButton, {}),
70
+ /* @__PURE__ */ jsx(CurdCreatePanelTriggerButton, {})
71
+ ] }) }) }) }),
72
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
73
+ ] })
74
+ ] });
75
+ };
76
+ const ListViewLayout = (props) => {
77
+ const layout = useListview((x) => x.layout);
78
+ const { children } = props;
79
+ const Layout = useMemo(() => {
80
+ switch (layout) {
81
+ case "demo":
82
+ return LzListViewLayoutDemo;
83
+ default:
84
+ return LzListViewLayoutDefault;
85
+ }
86
+ }, [layout]);
87
+ return /* @__PURE__ */ jsx(Layout, { children });
88
+ };
89
+ const ListViewLayoutSwitch = () => {
90
+ const layout = useListview((x) => x.layout);
91
+ const setLayout = useListview((x) => x.setLayout);
92
+ const [open, setOpen] = useState(false);
93
+ useHotkeys(HOTKEY_Listview_Switchlayout, () => {
94
+ setOpen((pre) => !pre);
95
+ }, [open, setOpen]);
96
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
97
+ /* @__PURE__ */ jsxs(DialogTitle, { children: [
98
+ "LayoutSwitch,",
99
+ layout
100
+ ] }),
101
+ /* @__PURE__ */ jsx("div", { className: "flex gap-2 bg-red-100 p-2", children: ALL_Layouts.map((layout2) => {
102
+ return /* @__PURE__ */ jsx(MtButton, { onClick: () => {
103
+ setLayout(layout2);
104
+ setOpen(false);
105
+ }, children: layout2 }, layout2);
106
+ }) })
107
+ ] }) });
108
+ };
109
+ export {
110
+ CommonListView,
111
+ ListViewActions,
112
+ LzListViewLayoutDefault,
113
+ LzListViewLayoutDemo
114
+ };
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { CommonListView } from "./ListViewProvider";
3
+ import { CommonListView } from "./CommonListView";
4
4
  import { Suspense } from "react";
5
5
  import CurdCreatePanel from "../create/CurdCreatePanel";
6
6
  import CurdEditPanel from "../edit/CurdEditPanel";
@@ -1,4 +1,6 @@
1
+ import { PlainMessage } from "@bufbuild/protobuf";
2
+ import { MtmError } from "./gomtmpb/mtm/sppb/mtm_pb";
1
3
  export declare const useGomtmQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseQueryResult<any, Error>;
2
4
  export declare const useGomtmSuspenseQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseSuspenseQueryResult<any, Error>;
3
- export declare const useGomtmSuspenseInfiniteQuery: (svc: string, method: string, input?: any) => import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<any, unknown>, Error>;
5
+ export declare function useGomtmSuspenseInfiniteQuery<T = any>(svc: string, method: string, input?: any): import("@tanstack/react-query").UseSuspenseInfiniteQueryResult<import("@tanstack/react-query").InfiniteData<T & PlainMessage<MtmError>, unknown>, Error>;
4
6
  export declare const useGomtmMutation: (svc: string, method: string) => import("@tanstack/react-query").UseMutationResult<any, Error, any, unknown>;
@@ -47,7 +47,7 @@ const useGomtmSuspenseQuery = (svc, method, input) => {
47
47
  });
48
48
  return query;
49
49
  };
50
- const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
50
+ function useGomtmSuspenseInfiniteQuery(svc, method, input) {
51
51
  const fn = useGmtmQjeryFn();
52
52
  const query = useSuspenseInfiniteQuery({
53
53
  queryKey: createInfiniteQueryKey(svc, method, input),
@@ -59,7 +59,7 @@ const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
59
59
  }
60
60
  });
61
61
  return query;
62
- };
62
+ }
63
63
  const useGomtmMutation = (svc, method) => {
64
64
  const fn = useGmtmQjeryFn();
65
65
  return useMutation({