gomtm 0.0.164 → 0.0.166

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
+ };
@@ -55,8 +55,6 @@ export declare const CurdViewView: (props: {
55
55
  export declare function useCurdView(): {
56
56
  curdView: CurdView;
57
57
  openShow: (id: string) => void;
58
- invalidateList: () => Promise<void>;
59
- invalidateGet: () => Promise<void>;
60
58
  activateId: string;
61
59
  setActivateId: (args_0: string | ((prev: string) => string)) => void;
62
60
  editLink: (id: string) => string;
@@ -1,24 +1,4 @@
1
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
2
  import { Fragment, jsx } from "react/jsx-runtime";
23
3
  import { useQueryClient } from "@tanstack/react-query";
24
4
  import { atom, createStore, useAtom } from "jotai";
@@ -28,7 +8,6 @@ import { compile, match } from "path-to-regexp";
28
8
  import { useCallback, useMemo } from "react";
29
9
  import { useSuspenseQuery } from "../connectquery";
30
10
  import { curdViewGet } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
31
- import { createInfiniteQueryKey, createQueryKey } from "../mtmquery";
32
11
  const activateIdAtom = atom("0");
33
12
  const curdViewAtom = atom(null);
34
13
  const curdViewIdAtom = atom("");
@@ -63,20 +42,6 @@ function useCurdView() {
63
42
  router.push(showLink(id));
64
43
  }
65
44
  }, [router, showLink]);
66
- const invalidateList = useCallback(() => __async(this, null, function* () {
67
- if (curdView) {
68
- yield queryClient.invalidateQueries({
69
- queryKey: createInfiniteQueryKey(curdView.svcName, curdView.methodList)
70
- });
71
- }
72
- }), [curdView, queryClient]);
73
- const invalidateGet = useCallback(() => __async(this, null, function* () {
74
- if (curdView) {
75
- yield queryClient.invalidateQueries({
76
- queryKey: createQueryKey(curdView.svcName, curdView.methodGet)
77
- });
78
- }
79
- }), [curdView, queryClient]);
80
45
  const editLink = useCallback((id) => {
81
46
  if (curdView == null ? void 0 : curdView.routeEdit) {
82
47
  const toPath = compile(curdView == null ? void 0 : curdView.routeEdit, { encode: encodeURIComponent });
@@ -106,8 +71,8 @@ function useCurdView() {
106
71
  return {
107
72
  curdView,
108
73
  openShow,
109
- invalidateList,
110
- invalidateGet,
74
+ // invalidateList,
75
+ // invalidateGet,
111
76
  activateId,
112
77
  setActivateId,
113
78
  editLink,
@@ -1,3 +0,0 @@
1
- export type * from '@tanstack/react-query';
2
- export declare function createQueryKey(svc: string, method: string, input?: any): any[];
3
- export declare function createInfiniteQueryKey(svc: string, method: string, input?: any): any[];
@@ -1,12 +1 @@
1
1
  "use client";
2
- import { camelCase, upperFirst } from "lodash";
3
- function createQueryKey(svc, method, input) {
4
- return [svc, upperFirst(camelCase(method)), input || {}];
5
- }
6
- function createInfiniteQueryKey(svc, method, input) {
7
- return [...createQueryKey(svc, method, input), "infinite"];
8
- }
9
- export {
10
- createInfiniteQueryKey,
11
- createQueryKey
12
- };
@@ -1,9 +1 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { ConnectError, PartialMessage } from '..';
3
- import { LoginReply, LoginReq } from '../gomtmpb/mtm/sppb/mtm_pb';
4
- import { UseMutationResult } from '../mtmquery';
5
- export declare function UserProvider(props: {} & PropsWithChildren): React.JSX.Element;
6
1
  export declare function isRoleMatch(currentRoles: string[], allowRoles?: string[]): boolean;
7
- export declare const useAuth: () => {
8
- login: UseMutationResult<LoginReply, ConnectError, PartialMessage<LoginReq>>;
9
- };
@@ -1,18 +1,4 @@
1
1
  "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import React from "react";
4
- import { useMutation, useSuspenseQuery } from "../connectquery";
5
- import { MtM_TOKEN_NAME } from "../consts";
6
- import { login, userinfo } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
7
- import { useToken } from "./GomtmProvider";
8
- const UserContext = React.createContext(void 0);
9
- function UserProvider(props) {
10
- const { children } = props;
11
- const query = useSuspenseQuery(userinfo, {});
12
- return /* @__PURE__ */ jsx(UserContext.Provider, { value: {
13
- userInfo: query.data
14
- }, children });
15
- }
16
2
  function isRoleMatch(currentRoles, allowRoles) {
17
3
  if (!currentRoles) {
18
4
  return true;
@@ -28,20 +14,6 @@ function isRoleMatch(currentRoles, allowRoles) {
28
14
  }
29
15
  return false;
30
16
  }
31
- const useAuth = () => {
32
- const { token, setToken } = useToken();
33
- const loginMutation = useMutation(login, {
34
- onSuccess(data, variables, context) {
35
- setToken(data.accessToken);
36
- document.cookie = `${MtM_TOKEN_NAME}=${data.accessToken}`;
37
- }
38
- });
39
- return {
40
- login: loginMutation
41
- };
42
- };
43
17
  export {
44
- UserProvider,
45
- isRoleMatch,
46
- useAuth
18
+ isRoleMatch
47
19
  };