gomtm 0.0.322 → 0.0.323

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,15 @@
1
+ import { PlainMessage } from "@bufbuild/protobuf";
2
+ import { PropsWithChildren } from "react";
3
+ import { 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 PostCardListItem: (props: {
11
+ item: PostCardItem;
12
+ }) => import("react").JSX.Element;
13
+ export declare const PostCardItemActions: (props: {
14
+ id: string;
15
+ }) => import("react").JSX.Element;
@@ -0,0 +1,185 @@
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 { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "mtxuilib/ui/card";
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
8
+ import { title } from "process";
9
+ import { useState } from "react";
10
+ import { MtDateView } from "../../components/MtDate";
11
+ import Tag from "../../components/Tag";
12
+ import { ListViewLayout } from "../../gomtmpb/mtm/sppb/mtm_pb";
13
+ import { useListview } from "../listview/list-store";
14
+ import { CommonListItemView } from "./CommonListItemView";
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 PostCardListItem = (props) => {
45
+ const { item } = props;
46
+ const slugPath = useListview((x) => x.slugPath);
47
+ const activateItem = useListview((x) => x.activateItem);
48
+ const setActivateItem = useListview((x) => x.setActivateItem);
49
+ if (item.layoutVariant == "list") {
50
+ 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: [
51
+ /* @__PURE__ */ jsxs("dl", { children: [
52
+ /* @__PURE__ */ jsx("dt", { className: "sr-only", children: "Published on" }),
53
+ /* @__PURE__ */ jsx("dd", { className: "text-base font-medium leading-6 text-gray-500 dark:text-gray-400", children: /* @__PURE__ */ jsx(MtDateView, { date: item.publishDate }) })
54
+ ] }),
55
+ /* @__PURE__ */ jsxs("div", { className: "space-y-5 xl:col-span-3", children: [
56
+ /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
57
+ /* @__PURE__ */ jsxs("div", { children: [
58
+ /* @__PURE__ */ jsx("h2", { className: "text-2xl font-bold leading-8 tracking-tight", children: /* @__PURE__ */ jsx(
59
+ MtLink,
60
+ {
61
+ href: `/blog/${item.slug}`,
62
+ className: "text-gray-900 dark:text-gray-100",
63
+ children: item.title
64
+ }
65
+ ) }),
66
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap", children: item.tags.map((tag) => /* @__PURE__ */ jsx(Tag, { text: tag }, tag)) })
67
+ ] }),
68
+ /* @__PURE__ */ jsx("div", { className: "prose max-w-none text-gray-500 dark:text-gray-400", children: item.summary })
69
+ ] }),
70
+ /* @__PURE__ */ jsx("div", { className: "text-base font-medium leading-6", children: /* @__PURE__ */ jsx(
71
+ MtLink,
72
+ {
73
+ href: `/blog/${item.slug}`,
74
+ className: "text-primary-500 hover:text-primary-600 dark:hover:text-primary-400",
75
+ "aria-label": `Read more: "${title}"`,
76
+ children: "Read more \u2192"
77
+ }
78
+ ) })
79
+ ] })
80
+ ] }) }) });
81
+ }
82
+ return /* @__PURE__ */ jsxs(
83
+ Card,
84
+ {
85
+ className: cn(
86
+ "m-2 w-[350px]",
87
+ item.id == (activateItem == null ? void 0 : activateItem.id) && " p-2 shadow-md"
88
+ ),
89
+ onClick: () => {
90
+ setActivateItem(item);
91
+ },
92
+ children: [
93
+ /* @__PURE__ */ jsxs(CardHeader, { children: [
94
+ /* @__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 }) }),
95
+ /* @__PURE__ */ jsx(CardDescription, { children: "Deploy your new project in one-click." })
96
+ ] }),
97
+ /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("article", { className: "my-4 flex flex-col", children: [
98
+ /* @__PURE__ */ jsx(MtLink, {
99
+ href: `${slugPath}/${item.id}`,
100
+ className: "hover:opacity-75",
101
+ // eslint-disable-next-line @next/next/no-img-element, jsx-a11y/alt-text
102
+ children: item.topImage && /* @__PURE__ */ jsx("img", { src: item.topImage, alt: item.title })
103
+ }),
104
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col justify-start bg-white p-6", children: [
105
+ /* @__PURE__ */ jsx(MtLink, { href: `${slugPath}/${item.id}`, className: "pb-4 text-sm font-bold uppercase text-blue-700", children: item.category || "news" }),
106
+ /* @__PURE__ */ jsxs("p", { className: "pb-3 text-sm", children: [
107
+ "By ",
108
+ /* @__PURE__ */ jsx(MtLink, { href: "#", children: item.author }),
109
+ ","
110
+ ] }),
111
+ /* @__PURE__ */ jsx("div", { children: item.excerpt })
112
+ ] })
113
+ ] }) }),
114
+ /* @__PURE__ */ jsxs(CardFooter, { className: "flex justify-end", children: [
115
+ /* @__PURE__ */ jsx(MtLink, { variant: "ghost", href: `${slugPath}/${item.id}`, children: "Show" }),
116
+ /* @__PURE__ */ jsx(PostCardItemActions, { id: item.id })
117
+ ] })
118
+ ]
119
+ }
120
+ );
121
+ };
122
+ const PostCardItemActions = (props) => {
123
+ const { id } = props;
124
+ const setOpenCreate = useListview((x) => x.setOpenCreate);
125
+ const setOpenRemove = useListview((x) => x.setOpenRemove);
126
+ const slugPath = useListview((x) => x.slugPath);
127
+ const [open, setOpen] = useState(false);
128
+ const setOpenEdit = useListview((x) => x.setOpenEdit);
129
+ return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, children: [
130
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
131
+ MtLink,
132
+ {
133
+ href: `${slugPath}/${id}`,
134
+ variant: "ghost",
135
+ className: "data-[state=open]:bg-muted flex size-8 p-0",
136
+ children: [
137
+ /* @__PURE__ */ jsx(Icons.chevronRight, { className: "size-4" }),
138
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "more" })
139
+ ]
140
+ }
141
+ ) }),
142
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-[160px]", children: [
143
+ /* @__PURE__ */ jsx(
144
+ DropdownMenuItem,
145
+ {
146
+ onClick: (e) => {
147
+ e.preventDefault();
148
+ setOpenCreate(true);
149
+ setOpen(false);
150
+ },
151
+ children: "create"
152
+ }
153
+ ),
154
+ /* @__PURE__ */ jsx(
155
+ DropdownMenuItem,
156
+ {
157
+ onClick: (e) => {
158
+ e.preventDefault();
159
+ setOpenEdit(true);
160
+ setOpen(false);
161
+ },
162
+ children: "edit"
163
+ }
164
+ ),
165
+ /* @__PURE__ */ jsx(
166
+ DropdownMenuItem,
167
+ {
168
+ onClick: (e) => {
169
+ e.preventDefault();
170
+ setOpenRemove(true);
171
+ setOpen(false);
172
+ },
173
+ children: "remove"
174
+ }
175
+ ),
176
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
177
+ ] })
178
+ ] });
179
+ };
180
+ export {
181
+ ListItemView,
182
+ ListViewLayoutRender,
183
+ PostCardItemActions,
184
+ PostCardListItem
185
+ };
@@ -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";