gomtm 0.0.368 → 0.0.369
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.
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
export default function CurdViewEditor(props: {
|
|
3
3
|
name: string;
|
|
4
4
|
}): import("react").JSX.Element;
|
|
5
|
-
export declare const CurdViewContentField: (
|
|
5
|
+
export declare const CurdViewContentField: (props: {
|
|
6
|
+
name: string;
|
|
7
|
+
}) => import("react").JSX.Element;
|
|
@@ -18,12 +18,11 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
22
|
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "mtxuilib/ui/form";
|
|
23
23
|
import { Input } from "mtxuilib/ui/input";
|
|
24
|
-
import { MtButton } from "mtxuilib/ui/ui-mt/Button";
|
|
25
24
|
import { useEffect } from "react";
|
|
26
|
-
import { useForm, useFormContext
|
|
25
|
+
import { useForm, useFormContext } from "react-hook-form";
|
|
27
26
|
import { FormShell } from "../../curd/form/FormShell";
|
|
28
27
|
function CurdViewEditor(props) {
|
|
29
28
|
const form = useFormContext();
|
|
@@ -40,10 +39,28 @@ function CurdViewEditor(props) {
|
|
|
40
39
|
] })
|
|
41
40
|
}
|
|
42
41
|
),
|
|
42
|
+
/* @__PURE__ */ jsx(CurdViewContentField, __spreadValues({}, form.register("content")))
|
|
43
|
+
] });
|
|
44
|
+
}
|
|
45
|
+
const CurdViewContentField = (props) => {
|
|
46
|
+
const { name } = props;
|
|
47
|
+
const form = useFormContext();
|
|
48
|
+
const defaultValues = form.getValues()[name];
|
|
49
|
+
console.log("defaultValues", defaultValues);
|
|
50
|
+
const contentForm = useForm({
|
|
51
|
+
defaultValues
|
|
52
|
+
});
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const subscription = contentForm.watch((value) => {
|
|
55
|
+
form.setValue(name, JSON.stringify(value, null, 2));
|
|
56
|
+
});
|
|
57
|
+
return () => subscription.unsubscribe();
|
|
58
|
+
}, [contentForm, contentForm.watch, form, name]);
|
|
59
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
43
60
|
/* @__PURE__ */ jsx(
|
|
44
61
|
FormField,
|
|
45
62
|
{
|
|
46
|
-
control:
|
|
63
|
+
control: contentForm.control,
|
|
47
64
|
name: "svcName",
|
|
48
65
|
render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
49
66
|
/* @__PURE__ */ jsx(FormLabel, { children: "Svc" }),
|
|
@@ -52,63 +69,38 @@ function CurdViewEditor(props) {
|
|
|
52
69
|
] })
|
|
53
70
|
}
|
|
54
71
|
),
|
|
55
|
-
/* @__PURE__ */ jsx(FormField, { control:
|
|
72
|
+
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "title", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
56
73
|
/* @__PURE__ */ jsx(FormLabel, { children: "title" }),
|
|
57
74
|
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "title" }, field)) }),
|
|
58
75
|
/* @__PURE__ */ jsx(FormMessage, {})
|
|
59
76
|
] }) }),
|
|
60
|
-
/* @__PURE__ */ jsx(FormField, { control:
|
|
77
|
+
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "methodList", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
61
78
|
/* @__PURE__ */ jsx(FormLabel, { children: "methodList" }),
|
|
62
79
|
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodList" }, field)) }),
|
|
63
80
|
/* @__PURE__ */ jsx(FormMessage, {})
|
|
64
81
|
] }) }),
|
|
65
|
-
/* @__PURE__ */ jsx(FormField, { control:
|
|
82
|
+
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "methodGet", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
66
83
|
/* @__PURE__ */ jsx(FormLabel, { children: "methodGet" }),
|
|
67
84
|
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodGet" }, field)) }),
|
|
68
85
|
/* @__PURE__ */ jsx(FormMessage, {})
|
|
69
86
|
] }) }),
|
|
70
|
-
/* @__PURE__ */ jsx(FormField, { control:
|
|
87
|
+
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "methodUpdate", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
71
88
|
/* @__PURE__ */ jsx(FormLabel, { children: "methodUpdate" }),
|
|
72
89
|
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodUpdate" }, field)) }),
|
|
73
90
|
/* @__PURE__ */ jsx(FormMessage, {})
|
|
74
91
|
] }) }),
|
|
75
|
-
/* @__PURE__ */ jsx(ChildB, { control: form.control }),
|
|
76
|
-
/* @__PURE__ */ jsx(CurdViewContentField, {})
|
|
77
|
-
] });
|
|
78
|
-
}
|
|
79
|
-
const CurdViewContentField = () => {
|
|
80
|
-
const form = useFormContext();
|
|
81
|
-
const contentForm = useForm();
|
|
82
|
-
const handleSubmit = (values) => {
|
|
83
|
-
console.log("submit content field", values);
|
|
84
|
-
form.setValue("content", JSON.stringify(values));
|
|
85
|
-
};
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
contentForm.watch();
|
|
88
|
-
}, []);
|
|
89
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
90
|
-
"CurdViewContentField",
|
|
91
92
|
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "someField", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
92
93
|
/* @__PURE__ */ jsx(FormLabel, { children: "someField" }),
|
|
93
94
|
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "someField" }, field)) }),
|
|
94
95
|
/* @__PURE__ */ jsx(FormMessage, {})
|
|
95
96
|
] }) }),
|
|
96
|
-
/* @__PURE__ */ jsx(
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
/* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "someField22", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
98
|
+
/* @__PURE__ */ jsx(FormLabel, { children: "someField" }),
|
|
99
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "someField" }, field)) }),
|
|
100
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
101
|
+
] }) })
|
|
99
102
|
] });
|
|
100
103
|
};
|
|
101
|
-
function ChildB(props) {
|
|
102
|
-
const { control } = props;
|
|
103
|
-
const firstName = useWatch({
|
|
104
|
-
control,
|
|
105
|
-
name: "title"
|
|
106
|
-
});
|
|
107
|
-
return /* @__PURE__ */ jsxs("div", { className: "bg-red-100 p-2", children: [
|
|
108
|
-
"Watch: ",
|
|
109
|
-
firstName
|
|
110
|
-
] });
|
|
111
|
-
}
|
|
112
104
|
export {
|
|
113
105
|
CurdViewContentField,
|
|
114
106
|
CurdViewEditor as default
|