gomtm 0.0.169 → 0.0.170
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.
- package/dist/esm/curd/CommonListViewV2.js +1 -1
- package/dist/esm/curd/list-item/ListItem.d.ts +6 -0
- package/dist/esm/curd/list-item/ListItem.js +49 -0
- package/dist/esm/form/ConnectEsUpdateForm.d.ts +17 -0
- package/dist/esm/form/ConnectEsUpdateForm.js +78 -0
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -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,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { MtLink } from "mtxuilib/common/mtlink";
|
|
4
|
+
import { cn } from "mtxuilib/lib/utils";
|
|
5
|
+
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
6
|
+
import { PostCard } from "../../components/blog/PostCard";
|
|
7
|
+
import { useCurdView } from "../CurdViewView";
|
|
8
|
+
const ListItemView = (props) => {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const { item } = props;
|
|
11
|
+
if ((_a = item == null ? void 0 : item.item) == null ? void 0 : _a.value) {
|
|
12
|
+
const itemCase = ((_b = item.item) == null ? void 0 : _b.case) || "";
|
|
13
|
+
switch (itemCase) {
|
|
14
|
+
case "commonListItem":
|
|
15
|
+
return /* @__PURE__ */ jsx(CommonListItemView, { item: item.item.value });
|
|
16
|
+
case "postCard":
|
|
17
|
+
return /* @__PURE__ */ jsx(PostCard, { item: item.item.value });
|
|
18
|
+
default:
|
|
19
|
+
return /* @__PURE__ */ jsx("span", { className: "bg-red-600 p-2", children: "unknow list item type" });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
const CommonListItemView = (props) => {
|
|
25
|
+
const { item } = props;
|
|
26
|
+
const curd = useCurdView();
|
|
27
|
+
const handleSelect = () => {
|
|
28
|
+
curd.openShow(item.id);
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
MtButton,
|
|
32
|
+
{
|
|
33
|
+
variant: "ghost",
|
|
34
|
+
onClick: handleSelect,
|
|
35
|
+
className: cn(
|
|
36
|
+
"flex min-h-16 justify-start border p-4 text-left",
|
|
37
|
+
item.id == curd.activateId && " font-bold"
|
|
38
|
+
),
|
|
39
|
+
"aria-label": item.id,
|
|
40
|
+
children: /* @__PURE__ */ jsxs(MtLink, { href: curd.showLink(item.id), children: [
|
|
41
|
+
item.title || item.id,
|
|
42
|
+
item.description && /* @__PURE__ */ jsx("div", { children: item.description })
|
|
43
|
+
] })
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
export {
|
|
48
|
+
ListItemView
|
|
49
|
+
};
|
|
@@ -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
|
+
};
|