gomtm 0.0.368 → 0.0.370

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,7 @@
2
2
  export default function CurdViewEditor(props: {
3
3
  name: string;
4
4
  }): import("react").JSX.Element;
5
- export declare const CurdViewContentField: () => import("react").JSX.Element;
5
+ export declare const CurdViewContentField: (props: {
6
+ name: string;
7
+ defaultValues: any;
8
+ }) => 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, useWatch } from "react-hook-form";
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,75 +39,40 @@ function CurdViewEditor(props) {
40
39
  ] })
41
40
  }
42
41
  ),
43
- /* @__PURE__ */ jsx(
44
- FormField,
45
- {
46
- control: form.control,
47
- name: "svcName",
48
- render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
49
- /* @__PURE__ */ jsx(FormLabel, { children: "Svc" }),
50
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "svcName" }, field)) }),
51
- /* @__PURE__ */ jsx(FormMessage, {})
52
- ] })
53
- }
54
- ),
55
42
  /* @__PURE__ */ jsx(FormField, { control: form.control, name: "title", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
56
43
  /* @__PURE__ */ jsx(FormLabel, { children: "title" }),
57
44
  /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "title" }, field)) }),
58
45
  /* @__PURE__ */ jsx(FormMessage, {})
59
46
  ] }) }),
60
- /* @__PURE__ */ jsx(FormField, { control: form.control, name: "methodList", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
61
- /* @__PURE__ */ jsx(FormLabel, { children: "methodList" }),
62
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodList" }, field)) }),
63
- /* @__PURE__ */ jsx(FormMessage, {})
64
- ] }) }),
65
- /* @__PURE__ */ jsx(FormField, { control: form.control, name: "methodGet", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
66
- /* @__PURE__ */ jsx(FormLabel, { children: "methodGet" }),
67
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodGet" }, field)) }),
68
- /* @__PURE__ */ jsx(FormMessage, {})
69
- ] }) }),
70
- /* @__PURE__ */ jsx(FormField, { control: form.control, name: "methodUpdate", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
71
- /* @__PURE__ */ jsx(FormLabel, { children: "methodUpdate" }),
72
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "methodUpdate" }, field)) }),
73
- /* @__PURE__ */ jsx(FormMessage, {})
74
- ] }) }),
75
- /* @__PURE__ */ jsx(ChildB, { control: form.control }),
76
- /* @__PURE__ */ jsx(CurdViewContentField, {})
47
+ /* @__PURE__ */ jsx(CurdViewContentField, { name: "content", defaultValues: form.getValues()["content"] })
77
48
  ] });
78
49
  }
79
- const CurdViewContentField = () => {
50
+ const CurdViewContentField = (props) => {
51
+ const { name, defaultValues } = props;
80
52
  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
- };
53
+ console.log("defaultValues", defaultValues);
54
+ const contentForm = useForm({
55
+ defaultValues
56
+ });
86
57
  useEffect(() => {
87
- contentForm.watch();
88
- }, []);
89
- return /* @__PURE__ */ jsxs("div", { children: [
90
- "CurdViewContentField",
58
+ const subscription = contentForm.watch((value) => {
59
+ form.setValue(name, JSON.stringify(value, null, 2));
60
+ });
61
+ return () => subscription.unsubscribe();
62
+ }, [contentForm, contentForm.watch, form, name]);
63
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
91
64
  /* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "someField", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
92
65
  /* @__PURE__ */ jsx(FormLabel, { children: "someField" }),
93
66
  /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "someField" }, field)) }),
94
67
  /* @__PURE__ */ jsx(FormMessage, {})
95
68
  ] }) }),
96
- /* @__PURE__ */ jsx(MtButton, { onClick: () => {
97
- handleSubmit(contentForm.getValues());
98
- }, children: "\u4FDD\u5B58" })
69
+ /* @__PURE__ */ jsx(FormField, { control: contentForm.control, name: "someField22", render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
70
+ /* @__PURE__ */ jsx(FormLabel, { children: "someField" }),
71
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: "someField" }, field)) }),
72
+ /* @__PURE__ */ jsx(FormMessage, {})
73
+ ] }) })
99
74
  ] });
100
75
  };
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
76
  export {
113
77
  CurdViewContentField,
114
78
  CurdViewEditor as default