gomtm 0.0.169 → 0.0.171

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.
@@ -4,10 +4,10 @@ import { atom, useAtom } from "jotai";
4
4
  import { useHydrateAtoms } from "jotai/utils";
5
5
  import { cn } from "mtxuilib/lib/utils";
6
6
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
7
- import { ListItemView } from "../components/ListItem";
8
7
  import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
9
8
  import { useSuspenseInfiniteQuery } from "../connectquery";
10
9
  import { ListViewLayout } from "../gomtmpb/mtm/sppb/mtm_pb";
10
+ import { ListItemView } from "./list-item/ListItem";
11
11
  const listQueryAtom = atom(null);
12
12
  function CommonListViewProvider(props) {
13
13
  const { children, methodList } = props;
@@ -0,0 +1,16 @@
1
+ import { AnyMessage, Message, PlainMessage } from "@bufbuild/protobuf";
2
+ import { PropsWithChildren } from "react";
3
+ import { MethodUnaryDescriptor } from "../connectquery";
4
+ export declare const curd3activateIdAtom: import("jotai").PrimitiveAtom<string> & {
5
+ init: string;
6
+ };
7
+ export declare function Curd3ListProvider<I extends Message<I>, O extends Message<O>>(props: {
8
+ params: Partial<PlainMessage<I>>;
9
+ methodList: MethodUnaryDescriptor<I, O>;
10
+ } & PropsWithChildren): import("react").JSX.Element;
11
+ export declare const useCurd3List: () => {
12
+ params: PlainMessage<AnyMessage>;
13
+ curd3MethodList: MethodUnaryDescriptor<AnyMessage, AnyMessage> | null;
14
+ };
15
+ export declare const Curd3ListViewDebug: () => import("react").JSX.Element;
16
+ export declare const Curd2ListView: () => import("react").JSX.Element;
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ var __async = (__this, __arguments, generator) => {
3
+ return new Promise((resolve, reject) => {
4
+ var fulfilled = (value) => {
5
+ try {
6
+ step(generator.next(value));
7
+ } catch (e) {
8
+ reject(e);
9
+ }
10
+ };
11
+ var rejected = (value) => {
12
+ try {
13
+ step(generator.throw(value));
14
+ } catch (e) {
15
+ reject(e);
16
+ }
17
+ };
18
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
19
+ step((generator = generator.apply(__this, __arguments)).next());
20
+ });
21
+ };
22
+ import { jsx, jsxs } from "react/jsx-runtime";
23
+ import { atom, useAtom } from "jotai";
24
+ import { ScopeProvider } from "mtxlib/jotai/ScopeProvider";
25
+ import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
26
+ import { callUnaryMethod } from "../connectquery";
27
+ import { gomtmBaseUrlAtom, transportAtom } from "../store/GomtmBackendProvider";
28
+ const curd3activateIdAtom = atom("");
29
+ const curd3ListParamsAtom = atom({});
30
+ const curd3MethodListAtom = atom(null);
31
+ const curd3ItemsAtom = atom((get) => __async(void 0, null, function* () {
32
+ const params = get(curd3ListParamsAtom);
33
+ const methodList = get(curd3MethodListAtom);
34
+ if (!methodList) {
35
+ throw new Error("curd3ItemsAtom, missing methodList");
36
+ }
37
+ const transport = get(transportAtom);
38
+ return yield callUnaryMethod(methodList, params, { transport });
39
+ }));
40
+ function Curd3ListProvider(props) {
41
+ const { params, methodList, children } = props;
42
+ return /* @__PURE__ */ jsx(ScopeProvider, { atoms: [curd3ListParamsAtom, curd3MethodListAtom], children: /* @__PURE__ */ jsx(AtomsHydrator, { atomValues: [
43
+ [curd3ListParamsAtom, params],
44
+ [curd3MethodListAtom, methodList]
45
+ ], children }) });
46
+ }
47
+ const useCurd3List = () => {
48
+ const [curd3ListParams] = useAtom(curd3ListParamsAtom);
49
+ const [curd3MethodList] = useAtom(curd3MethodListAtom);
50
+ return {
51
+ params: curd3ListParams,
52
+ curd3MethodList
53
+ };
54
+ };
55
+ const Curd3ListViewDebug = () => {
56
+ const curd3 = useCurd3List();
57
+ const [gomtmBaseUrl] = useAtom(gomtmBaseUrlAtom);
58
+ return /* @__PURE__ */ jsxs("div", { className: "bg-slate-200 p-2", children: [
59
+ /* @__PURE__ */ jsx("h1", { children: "Curd3ListViewDebug" }),
60
+ /* @__PURE__ */ jsxs("div", { children: [
61
+ "params: ",
62
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify(curd3, null, 2) })
63
+ ] }),
64
+ /* @__PURE__ */ jsxs("div", { children: [
65
+ "gomtmBaseUrl:",
66
+ gomtmBaseUrl
67
+ ] })
68
+ ] });
69
+ };
70
+ const Curd2ListView = () => {
71
+ const [items] = useAtom(curd3ItemsAtom);
72
+ return /* @__PURE__ */ jsx("div", { className: "bg-blue-100 p-2", children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(items, null, 2) }) });
73
+ };
74
+ export {
75
+ Curd2ListView,
76
+ Curd3ListProvider,
77
+ Curd3ListViewDebug,
78
+ curd3activateIdAtom,
79
+ useCurd3List
80
+ };
@@ -6,7 +6,7 @@ import { createContext, useMemo, useState } from "react";
6
6
  import { Icons } from "mtxuilib/icons/icons";
7
7
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
8
8
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
9
- import { activateIdAtom, useCurdView } from "./CurdViewView";
9
+ import { curd3activateIdAtom } from "./CurdListViewV3";
10
10
  const curdDetailViewContext = createContext(void 0);
11
11
  function CurdViewDetailProvider(props) {
12
12
  const [isOpenEdit, setIsOpenEdit] = useState(false);
@@ -17,7 +17,7 @@ function CurdViewDetailProvider(props) {
17
17
  }
18
18
  function CurdViewShow(props) {
19
19
  const { children } = props;
20
- const [activateId, setActivateId] = useAtom(activateIdAtom);
20
+ const [activateId, setActivateId] = useAtom(curd3activateIdAtom);
21
21
  const search = useSearchParams();
22
22
  useMemo(() => {
23
23
  const id = search.get("id");
@@ -31,7 +31,6 @@ function CurdViewShow(props) {
31
31
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(CurdViewDetailProvider, {}) });
32
32
  }
33
33
  const DetailViewActions = () => {
34
- const curd = useCurdView();
35
34
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
36
35
  /* @__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, {}) }) }),
37
36
  /* @__PURE__ */ jsxs(DropdownMenuContent, { className: "w-56", children: [
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "@bufbuild/protobuf";
3
+ import { ListItem } from "../../gomtmpb/mtm/sppb/mtm_pb";
4
+ export declare const ListItemView: (props: {
5
+ item: PlainMessage<ListItem>;
6
+ }) => import("react").JSX.Element | null;
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { cn } from "mtxuilib/lib/utils";
4
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
5
+ import { PostCard } from "../../components/blog/PostCard";
6
+ const ListItemView = (props) => {
7
+ var _a, _b;
8
+ const { item } = props;
9
+ if ((_a = item == null ? void 0 : item.item) == null ? void 0 : _a.value) {
10
+ const itemCase = ((_b = item.item) == null ? void 0 : _b.case) || "";
11
+ switch (itemCase) {
12
+ case "commonListItem":
13
+ return /* @__PURE__ */ jsx(CommonListItemView, { item: item.item.value });
14
+ case "postCard":
15
+ return /* @__PURE__ */ jsx(PostCard, { item: item.item.value });
16
+ default:
17
+ return /* @__PURE__ */ jsx("span", { className: "bg-red-600 p-2", children: "unknow list item type" });
18
+ }
19
+ }
20
+ return null;
21
+ };
22
+ const CommonListItemView = (props) => {
23
+ const { item } = props;
24
+ const handleSelect = () => {
25
+ };
26
+ return /* @__PURE__ */ jsx(
27
+ MtButton,
28
+ {
29
+ variant: "ghost",
30
+ onClick: handleSelect,
31
+ className: cn(
32
+ "flex min-h-16 justify-start border p-4 text-left"
33
+ // item.id == curd.activateId && " font-bold"
34
+ ),
35
+ "aria-label": item.id
36
+ }
37
+ );
38
+ };
39
+ export {
40
+ ListItemView
41
+ };
@@ -1,14 +1,10 @@
1
1
  "use client";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
- import { MtLink } from "mtxuilib/common/mtlink";
4
- import { useCurdView } from "./CurdViewView";
5
3
  const CurdEditButton = () => {
6
- const curd = useCurdView();
7
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MtLink, { variant: "ghost", href: curd.editLink(curd.activateId), children: "edit" }) });
4
+ return /* @__PURE__ */ jsx(Fragment, {});
8
5
  };
9
6
  const CurdCreateButton = () => {
10
- const curd = useCurdView();
11
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MtLink, { variant: "ghost", href: curd.createLink, children: "new" }) });
7
+ return /* @__PURE__ */ jsx(Fragment, {});
12
8
  };
13
9
  export {
14
10
  CurdCreateButton,
@@ -0,0 +1,17 @@
1
+ import { ComponentProps, PropsWithChildren } from "react";
2
+ import type { Message, PartialMessage } from "@bufbuild/protobuf";
3
+ import { ConnectQueryKey, MethodUnaryDescriptor } from "../connectquery";
4
+ export declare function ConnectEsUpdateForm<I extends Message<I>, O extends Message<O>>(props: {
5
+ defaultValues?: any;
6
+ mutationMethodSig: MethodUnaryDescriptor<any, any>;
7
+ onMutationSuccess?: ((data: any, variables: PartialMessage<any>, context: ConnectQueryKey<any>) => unknown) | undefined;
8
+ } & Omit<ComponentProps<typeof FormInnerWithSuspenseQuery>, "onSubmit">): import("react").JSX.Element;
9
+ declare function FormInner(props: {
10
+ defaultValues: any;
11
+ onSubmit: (values: any) => void;
12
+ } & PropsWithChildren): import("react").JSX.Element;
13
+ declare function FormInnerWithSuspenseQuery<I extends Message<I>, O extends Message<O>>(props: {
14
+ methodQuerySig: MethodUnaryDescriptor<I, O>;
15
+ params?: PartialMessage<I>;
16
+ } & Omit<ComponentProps<typeof FormInner>, "defaultValues">): import("react").JSX.Element;
17
+ export {};
@@ -0,0 +1,78 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+ import { Fragment, jsx } from "react/jsx-runtime";
34
+ import { Suspense, useMemo } from "react";
35
+ import { FormProvider, useForm } from "react-hook-form";
36
+ import { useMutation, useSuspenseQuery } from "../connectquery";
37
+ function ConnectEsUpdateForm(props) {
38
+ const { defaultValues, methodQuerySig, params, children, mutationMethodSig, onMutationSuccess } = props;
39
+ const mutation = useMutation(mutationMethodSig, {
40
+ onSuccess: onMutationSuccess
41
+ });
42
+ const handleSubmit = (values) => {
43
+ console.log("ConnectEsUpdateForm handle submit ", values, mutationMethodSig);
44
+ mutation.mutateAsync({ input: values });
45
+ };
46
+ return /* @__PURE__ */ jsx(Fragment, { children: defaultValues ? /* @__PURE__ */ jsx(FormInner, { defaultValues, onSubmit: handleSubmit, children }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Fragment, { children: "ConnectEsUpdateForm loading" }), children: /* @__PURE__ */ jsx(
47
+ FormInnerWithSuspenseQuery,
48
+ {
49
+ methodQuerySig,
50
+ params,
51
+ onSubmit: handleSubmit,
52
+ children
53
+ }
54
+ ) }) }) });
55
+ }
56
+ function FormInner(props) {
57
+ const { defaultValues, onSubmit, children } = props;
58
+ const form = useForm({
59
+ defaultValues
60
+ });
61
+ return /* @__PURE__ */ jsx(FormProvider, __spreadProps(__spreadValues({}, form), { children: /* @__PURE__ */ jsx("form", { onSubmit: form.handleSubmit(onSubmit), children }) }));
62
+ }
63
+ function FormInnerWithSuspenseQuery(props) {
64
+ const _a = props, { methodQuerySig, params, onSubmit } = _a, etc = __objRest(_a, ["methodQuerySig", "params", "onSubmit"]);
65
+ const query = useSuspenseQuery(methodQuerySig, params);
66
+ const defaultValue = useMemo(() => {
67
+ var _a2, _b;
68
+ const data2 = query.data;
69
+ if ((_a2 = data2.item) == null ? void 0 : _a2.value) {
70
+ return (_b = data2.item) == null ? void 0 : _b.value;
71
+ }
72
+ return query.data;
73
+ }, [query.data]);
74
+ return /* @__PURE__ */ jsx(FormInner, __spreadValues({ defaultValues: defaultValue, onSubmit }, etc));
75
+ }
76
+ export {
77
+ ConnectEsUpdateForm
78
+ };