gomtm 0.0.165 → 0.0.167

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.
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "@bufbuild/protobuf";
3
+ import { FormSchema } from "../../gomtmpb/mtm/sppb/mtm_pb";
4
+ export declare const SchemaFormFieldsRender: (props: {
5
+ schema: PlainMessage<FormSchema>;
6
+ }) => import("react").JSX.Element;
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __spreadValues = (a, b) => {
8
+ for (var prop in b || (b = {}))
9
+ if (__hasOwnProp.call(b, prop))
10
+ __defNormalProp(a, prop, b[prop]);
11
+ if (__getOwnPropSymbols)
12
+ for (var prop of __getOwnPropSymbols(b)) {
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ }
16
+ return a;
17
+ };
18
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
19
+ import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "mtxuilib/ui/form";
20
+ import { Input } from "mtxuilib/ui/input";
21
+ import { useFormContext } from "react-hook-form";
22
+ const SchemaFormFieldsRender = (props) => {
23
+ var _a;
24
+ const { schema } = props;
25
+ const form = useFormContext();
26
+ return /* @__PURE__ */ jsx(Fragment, { children: (_a = schema.fields) == null ? void 0 : _a.map((formField, i) => {
27
+ return /* @__PURE__ */ jsx(
28
+ FormField,
29
+ {
30
+ control: form.control,
31
+ name: formField.name,
32
+ defaultValue: formField.defaultValue || "",
33
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
34
+ formField.label && /* @__PURE__ */ jsx(FormLabel, { children: formField.label }),
35
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Input, __spreadValues({ placeholder: formField.placeholder }, field)) }) }),
36
+ formField.description && /* @__PURE__ */ jsx(FormDescription, { children: formField.description }),
37
+ /* @__PURE__ */ jsx(FormMessage, {})
38
+ ] })
39
+ },
40
+ i
41
+ );
42
+ }) });
43
+ };
44
+ export {
45
+ SchemaFormFieldsRender
46
+ };
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { PlainMessage } from "@bufbuild/protobuf";
3
+ import { MaybePromise } from "mtxlib";
4
+ import { FormSchema } from "../../gomtmpb/mtm/sppb/mtm_pb";
5
+ type SchemaFormViewVaranit = "auto" | "modal" | "card";
6
+ export declare const SchemaFormView: (props: {
7
+ formSchema?: PlainMessage<FormSchema> | undefined;
8
+ defaultValues?: any;
9
+ onSubmit: (values: any) => MaybePromise<void>;
10
+ onCancel?: (() => void) | undefined;
11
+ isLoading?: boolean | undefined;
12
+ variants?: SchemaFormViewVaranit | undefined;
13
+ }) => import("react").JSX.Element;
14
+ export {};
@@ -0,0 +1,44 @@
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
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
22
+ import { useState } from "react";
23
+ import { FormProvider, useForm } from "react-hook-form";
24
+ import { EditFormToolbar } from "mtxuilib/form/EditFormToolbar";
25
+ import { Card, CardContent } from "mtxuilib/ui/card";
26
+ import { DialogFooter } from "mtxuilib/ui/dialog";
27
+ import { SchemaFormFieldsRender } from "./SchemaFormFieldsRender";
28
+ const SchemaFormView = (props) => {
29
+ const { formSchema, onSubmit, onCancel, variants } = props;
30
+ const [defaultValues, setDefaultValues] = useState({});
31
+ const form = useForm({
32
+ defaultValues
33
+ });
34
+ if (!formSchema) {
35
+ return /* @__PURE__ */ jsx("div", { className: "border p-8", children: "missing formSchema params" });
36
+ }
37
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(FormProvider, __spreadProps(__spreadValues({}, form), { children: /* @__PURE__ */ jsx(Card, { className: "p-2", children: /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsxs("form", { onSubmit, children: [
38
+ /* @__PURE__ */ jsx(SchemaFormFieldsRender, { schema: formSchema }),
39
+ /* @__PURE__ */ jsx(DialogFooter, { children: /* @__PURE__ */ jsx(EditFormToolbar, { onCancel: () => onCancel && onCancel() }) })
40
+ ] }) }) }) })) });
41
+ };
42
+ export {
43
+ SchemaFormView
44
+ };