gomtm 0.0.190 → 0.0.192

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,11 +1,14 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useAtom } from "jotai";
3
4
  import { Icons } from "mtxuilib/icons/icons";
4
5
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
5
6
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
6
7
  import { DropdownMenuItemLink } from "mtxuilib/ui/ui-mt/DropdownMenuItemLink";
8
+ import { curdSlugPathAtom } from "../../curd/CommonListViewV2";
7
9
  const BlogPostItemActions = (props) => {
8
10
  const { postId } = props;
11
+ const [curdSlugPath] = useAtom(curdSlugPathAtom);
9
12
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10
13
  /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
11
14
  MtButton,
@@ -19,8 +22,10 @@ const BlogPostItemActions = (props) => {
19
22
  }
20
23
  ) }),
21
24
  /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-[160px]", children: [
22
- /* @__PURE__ */ jsx(DropdownMenuItemLink, { href: `/post/${postId}/edit`, children: "Edit" }),
23
25
  /* @__PURE__ */ jsx(DropdownMenuItemLink, { href: `/post/${postId}/create`, children: "create" }),
26
+ /* @__PURE__ */ jsx(DropdownMenuItemLink, { href: `/post/show`, children: "show" }),
27
+ /* @__PURE__ */ jsx(DropdownMenuItemLink, { href: `${curdSlugPath}/edit`, children: "edit" }),
28
+ /* @__PURE__ */ jsx(DropdownMenuItemLink, { href: `${curdSlugPath}/listdebug`, children: "list debug" }),
24
29
  /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
25
30
  /* @__PURE__ */ jsxs(DropdownMenuItem, { children: [
26
31
  "Delete",
@@ -0,0 +1,7 @@
1
+ import { Message } from "@bufbuild/protobuf";
2
+ import { PropsWithChildren } from "react";
3
+ import { MethodUnaryDescriptor } from "../connectquery";
4
+ export declare function CommonListViewProvider<I extends Message<I>, O extends Message<O>>(props: {
5
+ methodList: MethodUnaryDescriptor<I, any>;
6
+ } & PropsWithChildren): import("react").JSX.Element;
7
+ export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
@@ -0,0 +1,81 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { atom, useAtom } from "jotai";
4
+ import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
5
+ import { cn } from "mtxuilib/lib/utils";
6
+ import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
7
+ import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
8
+ import { useSuspenseInfiniteQuery } from "../connectquery";
9
+ import { ListViewLayout } from "../gomtmpb/mtm/sppb/mtm_pb";
10
+ import { ListItemView } from "./list-item/ListItem";
11
+ const listQueryAtom = atom(null);
12
+ function CommonListViewProvider(props) {
13
+ const { children, methodList } = props;
14
+ const listquery = useSuspenseInfiniteQuery(methodList, {
15
+ //@ts-expect-error
16
+ page: 1
17
+ }, {
18
+ pageParamKey: "pagination",
19
+ getNextPageParam: (res, b, c) => {
20
+ return {
21
+ //@ts-expect-error
22
+ page: ((c == null ? void 0 : c.page) || 0) + 1
23
+ };
24
+ }
25
+ });
26
+ return /* @__PURE__ */ jsx(ScopeAtomsHydrator, { atomValues: [
27
+ [listQueryAtom, listquery]
28
+ ], children });
29
+ }
30
+ function CommonListView() {
31
+ const [listQuery, setListQuery] = useAtom(listQueryAtom);
32
+ if (!(listQuery == null ? void 0 : listQuery.data)) {
33
+ return null;
34
+ }
35
+ return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
36
+ /* @__PURE__ */ jsx(
37
+ "div",
38
+ {
39
+ className: cn(
40
+ "w-full"
41
+ // 滚动设置
42
+ // " max-h-[700px] overflow-y-auto"
43
+ ),
44
+ children: listQuery.data.pages.map((page, i) => {
45
+ var _a;
46
+ if (page.error_code) {
47
+ return /* @__PURE__ */ jsx(MtUnaryCallErrorView, { unaryError: page }, i);
48
+ } else {
49
+ return /* @__PURE__ */ jsx(ListLayout, { 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);
50
+ }
51
+ })
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsx(Pagination, { children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
55
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, { href: "#" }) }),
56
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "1" }) }),
57
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", isActive: true, children: "2" }) }),
58
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "3" }) }),
59
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
60
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
61
+ ] }) }),
62
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1" })
63
+ ] });
64
+ }
65
+ const ListLayout = (props) => {
66
+ const { children } = props;
67
+ switch (props.layout) {
68
+ case ListViewLayout.simple:
69
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col space-y-1 rounded-md p-2 shadow-sm", children });
70
+ case ListViewLayout.grid:
71
+ return /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3", children });
72
+ case ListViewLayout.card:
73
+ return /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 grid-rows-3 gap-4 px-4 lg:grid-cols-3", children });
74
+ default:
75
+ return children;
76
+ }
77
+ };
78
+ export {
79
+ CommonListView,
80
+ CommonListViewProvider
81
+ };
@@ -1,7 +1,9 @@
1
1
  import { Message } from "@bufbuild/protobuf";
2
2
  import { PropsWithChildren } from "react";
3
3
  import { MethodUnaryDescriptor } from "../connectquery";
4
+ export declare const curdSlugPathAtom: import("jotai").Atom<string>;
4
5
  export declare function CommonListViewProvider<I extends Message<I>, O extends Message<O>>(props: {
5
6
  methodList: MethodUnaryDescriptor<I, any>;
7
+ slugPath?: string;
6
8
  } & PropsWithChildren): import("react").JSX.Element;
7
9
  export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { atom, useAtom } from "jotai";
4
- import { useHydrateAtoms } from "jotai/utils";
4
+ import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
5
5
  import { cn } from "mtxuilib/lib/utils";
6
6
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
7
7
  import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
@@ -9,8 +9,16 @@ import { useSuspenseInfiniteQuery } from "../connectquery";
9
9
  import { ListViewLayout } from "../gomtmpb/mtm/sppb/mtm_pb";
10
10
  import { ListItemView } from "./list-item/ListItem";
11
11
  const listQueryAtom = atom(null);
12
+ const curdSlugPathValueAtom = atom("");
13
+ const curdSlugPathAtom = atom((get) => {
14
+ const value = get(curdSlugPathValueAtom);
15
+ if (value == "/") {
16
+ return "";
17
+ }
18
+ return value || "";
19
+ });
12
20
  function CommonListViewProvider(props) {
13
- const { children, methodList } = props;
21
+ const { children, methodList, slugPath } = props;
14
22
  const listquery = useSuspenseInfiniteQuery(methodList, {
15
23
  //@ts-expect-error
16
24
  page: 1
@@ -23,13 +31,10 @@ function CommonListViewProvider(props) {
23
31
  };
24
32
  }
25
33
  });
26
- useHydrateAtoms([
27
- [
28
- listQueryAtom,
29
- listquery
30
- ]
31
- ]);
32
- return /* @__PURE__ */ jsx(Fragment, { children });
34
+ return /* @__PURE__ */ jsx(ScopeAtomsHydrator, { atomValues: [
35
+ [listQueryAtom, listquery],
36
+ [curdSlugPathValueAtom, slugPath]
37
+ ], children });
33
38
  }
34
39
  function CommonListView() {
35
40
  const [listQuery, setListQuery] = useAtom(listQueryAtom);
@@ -81,5 +86,6 @@ const ListLayout = (props) => {
81
86
  };
82
87
  export {
83
88
  CommonListView,
84
- CommonListViewProvider
89
+ CommonListViewProvider,
90
+ curdSlugPathAtom
85
91
  };
@@ -2,5 +2,6 @@ import { PropsWithChildren } from "react";
2
2
  export declare const curdDetailSlugAtom: import("jotai").PrimitiveAtom<string> & {
3
3
  init: string;
4
4
  };
5
- export declare function CurdViewDetail<T = any>(props: PropsWithChildren): import("react").JSX.Element;
5
+ export declare function CurdViewDetailProvider<T = any>(props: PropsWithChildren): import("react").JSX.Element;
6
+ export declare const CurdViewDetailDefault: () => import("react").JSX.Element;
6
7
  export declare const DetailViewActions: () => import("react").JSX.Element;
@@ -1,6 +1,5 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useMemo } from "react";
4
3
  import { atom, useAtom } from "jotai";
5
4
  import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
6
5
  import { Icons } from "mtxuilib/icons/icons";
@@ -10,28 +9,25 @@ import { usePathname } from "next/navigation";
10
9
  import { useSuspenseQuery } from "../connectquery";
11
10
  import { SchemaFormView } from "../form/SchemaFormView";
12
11
  import { curdDetail } from "../gomtmpb/mtm/sppb/curd-CurdService_connectquery";
12
+ import { curdViewGet } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
13
+ import { useCurdSlugName } from "./curd.atoms";
13
14
  const curdDetailSlugAtom = atom("");
14
- function CurdViewDetail(props) {
15
+ function CurdViewDetailProvider(props) {
15
16
  const { children } = props;
16
17
  const pathName = usePathname();
17
- return /* @__PURE__ */ jsxs(ScopeAtomsHydrator, { atomValues: [
18
+ return /* @__PURE__ */ jsx(ScopeAtomsHydrator, { atomValues: [
18
19
  [curdDetailSlugAtom, pathName]
19
- ], children: [
20
- /* @__PURE__ */ jsx(CurdViewDetailInner, {}),
21
- children
22
- ] });
20
+ ], children });
23
21
  }
24
- const CurdViewDetailInner = () => {
22
+ const CurdViewDetailDefault = () => {
25
23
  var _a, _b, _c, _d;
26
24
  const [slugPath] = useAtom(curdDetailSlugAtom);
27
- const slug = useMemo(() => {
28
- const path2 = slugPath.split("/");
29
- if (path2.length >= 2) {
30
- return path2[2];
31
- }
32
- }, [slugPath]);
25
+ const nameSlug = useCurdSlugName();
33
26
  const detailQuery = useSuspenseQuery(curdDetail, {
34
- slug
27
+ slug: nameSlug
28
+ });
29
+ const curdGetQuery = useSuspenseQuery(curdViewGet, {
30
+ name: nameSlug
35
31
  });
36
32
  if ((_b = (_a = detailQuery.data) == null ? void 0 : _a.detailView) == null ? void 0 : _b.form) {
37
33
  return /* @__PURE__ */ jsx(
@@ -44,7 +40,10 @@ const CurdViewDetailInner = () => {
44
40
  }
45
41
  );
46
42
  }
47
- return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(detailQuery.data, null, 2) }) });
43
+ return /* @__PURE__ */ jsxs("div", { children: [
44
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify(detailQuery.data, null, 2) }),
45
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify(curdGetQuery.data, null, 2) })
46
+ ] });
48
47
  };
49
48
  const DetailViewActions = () => {
50
49
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
@@ -58,7 +57,8 @@ const DetailViewActions = () => {
58
57
  ] });
59
58
  };
60
59
  export {
61
- CurdViewDetail,
60
+ CurdViewDetailDefault,
61
+ CurdViewDetailProvider,
62
62
  DetailViewActions,
63
63
  curdDetailSlugAtom
64
64
  };
@@ -13,3 +13,4 @@ export declare const curdPathAtom: import("jotai").PrimitiveAtom<string> & {
13
13
  init: string;
14
14
  };
15
15
  export declare const curd3ItemsV2Atom: import("jotai").Atom<Promise<CommontListRes>>;
16
+ export declare const useCurdSlugName: () => string | undefined;
@@ -22,6 +22,8 @@ var __async = (__this, __arguments, generator) => {
22
22
  import { atom } from "jotai";
23
23
  import { CommontListRes } from "../gomtmpb/mtm/sppb/mtm_pb";
24
24
  import { gomtmBaseUrlAtom } from "../providers/GomtmProvider";
25
+ import { usePathname } from "next/navigation";
26
+ import { useMemo } from "react";
25
27
  const curdDashPathPrefixAtom = atom("/gomtmadmin");
26
28
  const curdActivateIdAtom = atom("");
27
29
  const curd3ListParamsAtom = atom({});
@@ -36,10 +38,21 @@ const curd3ItemsV2Atom = atom((get) => __async(void 0, null, function* () {
36
38
  const data2 = CommontListRes.fromJson(data);
37
39
  return data2;
38
40
  }));
41
+ const useCurdSlugName = () => {
42
+ const pathname = usePathname();
43
+ const nameSlug = useMemo(() => {
44
+ const a = pathname.split("/");
45
+ if (a.length >= 2) {
46
+ return a[2];
47
+ }
48
+ }, [pathname]);
49
+ return nameSlug;
50
+ };
39
51
  export {
40
52
  curd3ItemsV2Atom,
41
53
  curd3ListParamsAtom,
42
54
  curdActivateIdAtom,
43
55
  curdDashPathPrefixAtom,
44
- curdPathAtom
56
+ curdPathAtom,
57
+ useCurdSlugName
45
58
  };