gomtm 0.0.267 → 0.0.269

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,2 @@
1
+ /// <reference types="react" />
2
+ export declare const GoMtmDebug: () => import("react").JSX.Element | null;
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { Icons } from "mtxuilib/icons/icons";
4
+ import { CommandDialog, CommandEmpty, CommandInput, CommandList, CommandSeparator } from "mtxuilib/ui/command";
5
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
6
+ import { useState } from "react";
7
+ import { useMtmApp } from "../../providers/GomtmProvider";
8
+ const GoMtmDebug = () => {
9
+ const [open, setOpen] = useState(false);
10
+ const mtapp = useMtmApp();
11
+ if (!mtapp.isDebug) {
12
+ return null;
13
+ }
14
+ return /* @__PURE__ */ jsxs("div", { className: "fixed bottom-12 right-2 bg-red-300", children: [
15
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => {
16
+ setOpen(true);
17
+ }, children: /* @__PURE__ */ jsx(Icons.bug, {}) }),
18
+ /* @__PURE__ */ jsxs(CommandDialog, { open, onOpenChange: setOpen, children: [
19
+ /* @__PURE__ */ jsx(CommandInput, { placeholder: "Type a command or search...", onValueChange: (s) => {
20
+ setOpen(false);
21
+ } }),
22
+ /* @__PURE__ */ jsxs(CommandList, { children: [
23
+ /* @__PURE__ */ jsx(CommandEmpty, { children: "No results found." }),
24
+ /* @__PURE__ */ jsx(CommandSeparator, {})
25
+ ] })
26
+ ] })
27
+ ] });
28
+ };
29
+ export {
30
+ GoMtmDebug
31
+ };
@@ -26,3 +26,5 @@ export declare const ImageNoExist = "/images/404.jpg";
26
26
  export declare const ADMIN_ROLE = "admin";
27
27
  export declare const MEMBER_ROLE = "member";
28
28
  export declare const TRPC_API_PREFIX = "/api.v1/trpc";
29
+ export declare const HOTKEY_Debug = "alt+j";
30
+ export declare const HOTKEY_Switchlayout = "alt+l";
@@ -26,6 +26,8 @@ const ImageNoExist = "/images/404.jpg";
26
26
  const ADMIN_ROLE = "admin";
27
27
  const MEMBER_ROLE = "member";
28
28
  const TRPC_API_PREFIX = "/api.v1/trpc";
29
+ const HOTKEY_Debug = "alt+j";
30
+ const HOTKEY_Switchlayout = "alt+l";
29
31
  export {
30
32
  ADMIN_ROLE,
31
33
  ActionCreate,
@@ -38,6 +40,8 @@ export {
38
40
  Cookie_Site_Host,
39
41
  DEFAULT_revalidate_SECONDS,
40
42
  ExtKey_Hostname,
43
+ HOTKEY_Debug,
44
+ HOTKEY_Switchlayout,
41
45
  HeaderMtmApi,
42
46
  HeaderMtmHost,
43
47
  ImageNoExist,
@@ -1,13 +1,16 @@
1
1
  import { Message } from "@bufbuild/protobuf";
2
2
  import { Dispatch, PropsWithChildren, SetStateAction } from "react";
3
3
  import { MethodUnaryDescriptor } from "../connectquery";
4
- export declare function ListViewProvider<I extends Message<I>, O extends Message<O>>(props: {
4
+ interface ListViewProps<I extends Message<I>, O extends Message<O>> {
5
5
  methodList: MethodUnaryDescriptor<I, any>;
6
6
  methodDelete: MethodUnaryDescriptor<any, any>;
7
7
  methodCreate?: MethodUnaryDescriptor<any, any>;
8
8
  slugPath?: string;
9
- } & PropsWithChildren): import("react").JSX.Element;
10
- export declare const useListView: () => {
9
+ activateItem?: any;
10
+ params?: any;
11
+ }
12
+ export declare function ListViewProvider<I extends Message<I>, O extends Message<O>>(props: ListViewProps<I, O> & PropsWithChildren): import("react").JSX.Element;
13
+ export declare function useListView<I extends Message<I>, O extends Message<O>>(): {
11
14
  methodList?: MethodUnaryDescriptor<any, any> | undefined;
12
15
  methodDelete?: MethodUnaryDescriptor<any, any> | undefined;
13
16
  methodCreate?: MethodUnaryDescriptor<any, any> | undefined;
@@ -27,3 +30,4 @@ export declare const useListView: () => {
27
30
  };
28
31
  export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
29
32
  export declare const ListViewActions: () => import("react").JSX.Element;
33
+ export {};
@@ -45,9 +45,10 @@ import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
45
45
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
46
46
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
47
47
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
48
- import { Suspense, createContext, useContext, useState } from "react";
48
+ import { Suspense, createContext, useContext, useMemo, useState } from "react";
49
49
  import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
50
50
  import { useMutation, useSuspenseInfiniteQuery } from "../connectquery";
51
+ import { useMtmApp } from "../providers/GomtmProvider";
51
52
  import { DlgCurdDebugInfo, DlgCurdDebugInfoTriggerButton } from "./CurdDetailProvider";
52
53
  import CurdCreatePanel, { CurdCreatePanelTriggerButton } from "./create/CurdCreatePanel";
53
54
  import CurdEditPanel, { CurdEditPanelTriggerButton } from "./edit/CurdEditPanel";
@@ -56,12 +57,19 @@ import { ListLayout } from "./list-item/ListLayout";
56
57
  const commonListViewContext = createContext(void 0);
57
58
  function ListViewProvider(props) {
58
59
  const { children, methodList, methodDelete, slugPath, methodCreate } = props;
60
+ const mtapp = useMtmApp();
59
61
  const [openRemove, setOpenRemove] = useState(false);
60
62
  const [openCreate, setOpenCreate] = useState(false);
61
63
  const [activateItem, setActivateItem] = useState(void 0);
62
64
  const [openEdit, setOpenEdit] = useState(false);
63
65
  const [openDebug, setOpenDebug] = useState(false);
64
- const [params, setParams] = useState(void 0);
66
+ const [_params, setParams] = useState(mtapp.globalSearchParams);
67
+ const params = useMemo(() => {
68
+ var _a;
69
+ return {
70
+ q: (_a = mtapp.globalSearchParams) == null ? void 0 : _a.q
71
+ };
72
+ }, [mtapp.globalSearchParams]);
65
73
  return /* @__PURE__ */ jsx(commonListViewContext.Provider, { value: {
66
74
  methodList,
67
75
  slugPath,
@@ -81,13 +89,16 @@ function ListViewProvider(props) {
81
89
  setParams
82
90
  }, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading list" }), children }) });
83
91
  }
84
- const useListView = () => {
92
+ function useListView() {
85
93
  const ctx = useContext(commonListViewContext);
86
94
  return __spreadValues({}, ctx);
87
- };
95
+ }
88
96
  function CommonListView() {
89
- const a = useListView();
90
- const listQuery = useSuspenseInfiniteQuery(a.methodList, {
97
+ const listView = useListView();
98
+ const listQuery = useSuspenseInfiniteQuery(listView.methodList, {
99
+ Params: {
100
+ q: listView.params.q
101
+ },
91
102
  pagination: {
92
103
  page: 1
93
104
  }
@@ -95,15 +106,15 @@ function CommonListView() {
95
106
  pageParamKey: "pagination",
96
107
  getNextPageParam: (lastPage, allPages, lastPageParam, allPageParams) => {
97
108
  var _a;
98
- const a2 = __spreadProps(__spreadValues({}, lastPageParam), { page: (((_a = lastPage.Pagination) == null ? void 0 : _a.page) || 1) + 1 });
99
- console.log("getNextPageParam", a2);
100
- return a2;
109
+ const a = __spreadProps(__spreadValues({}, lastPageParam), { page: (((_a = lastPage.Pagination) == null ? void 0 : _a.page) || 1) + 1 });
110
+ return a;
101
111
  }
102
112
  });
103
113
  if (!(listQuery == null ? void 0 : listQuery.data)) {
104
114
  return null;
105
115
  }
106
116
  return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
117
+ JSON.stringify(listView.params, null, 2),
107
118
  /* @__PURE__ */ jsx(
108
119
  "div",
109
120
  {
@@ -10,6 +10,7 @@ import { AppProgressBar as ProgressBar } from "next-nprogress-bar";
10
10
  import { Suspense, lazy } from "react";
11
11
  import { useHotkeys } from "react-hotkeys-hook";
12
12
  import { Toaster } from "sonner";
13
+ import { HOTKEY_Switchlayout } from "../consts";
13
14
  import { useMtmApp } from "../providers/GomtmProvider";
14
15
  const ALL_Layouts = [
15
16
  "demo1",
@@ -29,10 +30,7 @@ const LayoutBase = (props) => {
29
30
  " ",
30
31
  children,
31
32
  " "
32
- ] }) : (
33
- // layoutName == "front" ? <FrontLayout>{children}</FrontLayout> :
34
- layoutName == "dash5" ? /* @__PURE__ */ jsx(LzDash5, { children }) : layoutName == "debug" ? /* @__PURE__ */ jsx(LzDebugLayout, { children }) : layoutName == "demo1" ? /* @__PURE__ */ jsx(LzDemoLayout, { children }) : layoutName == "default" ? /* @__PURE__ */ jsx(Fragment, { children }) : children
35
- ),
33
+ ] }) : layoutName == "dash5" ? /* @__PURE__ */ jsx(LzDash5, { children }) : layoutName == "debug" ? /* @__PURE__ */ jsx(LzDebugLayout, { children }) : layoutName == "demo1" ? /* @__PURE__ */ jsx(LzDemoLayout, { children }) : layoutName == "default" ? /* @__PURE__ */ jsx(Fragment, { children }) : children,
36
34
  /* @__PURE__ */ jsx(
37
35
  ProgressBar,
38
36
  {
@@ -51,9 +49,9 @@ const LayoutBase = (props) => {
51
49
  };
52
50
  const LayoutSwitchDlg = () => {
53
51
  const mtapp = useMtmApp();
54
- useHotkeys("alt+l", () => {
55
- mtapp.setOpenLayoutSwitchDlg(!mtapp.openLayoutSwitchDlg);
56
- }, []);
52
+ useHotkeys(HOTKEY_Switchlayout, () => {
53
+ mtapp.setOpenLayoutSwitchDlg((pre) => !pre);
54
+ }, [mtapp.setOpenLayoutSwitchDlg, mtapp.openLayoutSwitchDlg]);
57
55
  return /* @__PURE__ */ jsx(Dialog, { open: mtapp.openLayoutSwitchDlg, onOpenChange: mtapp.setOpenLayoutSwitchDlg, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
58
56
  /* @__PURE__ */ jsxs(DialogTitle, { children: [
59
57
  "LayoutSwitch,",
@@ -26,11 +26,15 @@ import { MtForm } from "mtxuilib/ui/ui-mt/MtForm";
26
26
  import { useState } from "react";
27
27
  import { useForm } from "react-hook-form";
28
28
  import { useHotkeys } from "react-hotkeys-hook";
29
+ import { useGlobalsearchParams, useMtmApp } from "../../providers/GomtmProvider";
29
30
  const PageSearchCmd = () => {
31
+ var _a;
30
32
  const [open, setOpen] = useState(false);
31
33
  useHotkeys("alt+s", () => {
32
34
  setOpen((open2) => !open2);
33
35
  }, []);
36
+ const mtapp = useMtmApp();
37
+ const search = useGlobalsearchParams();
34
38
  const form = useForm();
35
39
  return /* @__PURE__ */ jsxs(MtForm, __spreadProps(__spreadValues({}, form), { children: [
36
40
  /* @__PURE__ */ jsx("form", { onSubmit: form.handleSubmit(() => {
@@ -42,7 +46,11 @@ const PageSearchCmd = () => {
42
46
  type: "search",
43
47
  placeholder: "Search...",
44
48
  className: "bg-background w-full rounded-lg pl-8 md:w-[200px] lg:w-[336px]",
49
+ defaultValue: (_a = search.searchParams) == null ? void 0 : _a.q,
45
50
  onChange: (e) => {
51
+ search.setSearchParams({
52
+ q: e.target.value
53
+ });
46
54
  }
47
55
  }
48
56
  )
@@ -18,6 +18,8 @@ export declare function useMtmApp(): {
18
18
  openLayoutSwitchDlg?: boolean | undefined;
19
19
  setOpenLayoutSwitchDlg: Dispatch<SetStateAction<boolean>>;
20
20
  setCookieStr: Dispatch<SetStateAction<string>>;
21
+ globalSearchParams?: any;
22
+ setGlobalSearchParams: Dispatch<any>;
21
23
  backendUrl?: string | null | undefined;
22
24
  isDebug?: boolean | undefined;
23
25
  layoutName?: string | undefined;
@@ -25,4 +27,8 @@ export declare function useMtmApp(): {
25
27
  };
26
28
  export declare const useHostname: () => string;
27
29
  export declare const MtConnectProvider: (props: PropsWithChildren) => import("react").JSX.Element;
30
+ export declare const useGlobalsearchParams: () => {
31
+ searchParams: any;
32
+ setSearchParams: Dispatch<any>;
33
+ };
28
34
  export {};
@@ -1,5 +1,7 @@
1
1
  "use client";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
3
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -15,11 +17,16 @@ var __spreadValues = (a, b) => {
15
17
  }
16
18
  return a;
17
19
  };
18
- import { jsx } from "react/jsx-runtime";
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ import { jsx, jsxs } from "react/jsx-runtime";
19
22
  import { createContext, useContext, useMemo, useState } from "react";
20
23
  import { createConnectTransport } from "@connectrpc/connect-web";
24
+ import { debounce } from "lodash";
25
+ import { useSearchParams } from "next/navigation";
21
26
  import { useHotkeys } from "react-hotkeys-hook";
27
+ import { GoMtmDebug } from "../components/devtools/GoMtmDebug";
22
28
  import { TransportProvider } from "../connectquery";
29
+ import { HOTKEY_Debug } from "../consts";
23
30
  import { anypbTypeReg } from "../messageTypeRegistry";
24
31
  import { gomtmFetcher } from "../mtmFetcher";
25
32
  import { MtReactQueryProvider } from "./ReactQueryProvider";
@@ -31,9 +38,23 @@ function GomtmProvider(props) {
31
38
  const [_layoutName, setLayoutName] = useState("front");
32
39
  const [openLayoutSwitchDlg, setOpenLayoutSwitchDlg] = useState(false);
33
40
  const [_cookieStr, setCookieStr] = useState("");
34
- useHotkeys("alt+j", () => {
35
- setDebug(!_isDebug);
41
+ const [_globalSearchParams, setGlobalSearchParams] = useState({});
42
+ useHotkeys(HOTKEY_Debug, () => {
43
+ console.log("set debug");
44
+ setDebug((pre) => !pre);
36
45
  }, [_isDebug, setDebug]);
46
+ const searchParams = useSearchParams();
47
+ const globalSearchParams = useMemo(() => {
48
+ debounce(() => {
49
+ const q = searchParams.get("q");
50
+ console.log("search changed", q);
51
+ if (q) {
52
+ setGlobalSearchParams((pre) => {
53
+ return __spreadProps(__spreadValues({}, pre), { q });
54
+ });
55
+ }
56
+ }, 500);
57
+ }, [searchParams]);
37
58
  return /* @__PURE__ */ jsx(AppContext.Provider, { value: {
38
59
  isDebug: _isDebug,
39
60
  setIsDebug: setDebug,
@@ -44,13 +65,18 @@ function GomtmProvider(props) {
44
65
  openLayoutSwitchDlg,
45
66
  setOpenLayoutSwitchDlg,
46
67
  cookieStr: _cookieStr,
47
- setCookieStr
48
- }, children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsx(MtReactQueryProvider, { children }) }) });
68
+ setCookieStr,
69
+ globalSearchParams,
70
+ setGlobalSearchParams
71
+ }, children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsxs(MtReactQueryProvider, { children: [
72
+ children,
73
+ /* @__PURE__ */ jsx(GoMtmDebug, {})
74
+ ] }) }) });
49
75
  }
50
76
  function useMtmApp() {
51
77
  const mtappContext = useContext(AppContext);
52
78
  if (mtappContext === void 0) {
53
- throw new Error("useMtmApp must be used within a MtAppProvider");
79
+ throw new Error("useMtmApp must be used within a GomtmProvider");
54
80
  }
55
81
  return __spreadValues({}, mtappContext);
56
82
  }
@@ -80,9 +106,17 @@ const MtConnectProvider = (props) => {
80
106
  }, [mtapp.backendUrl, mtapp.cookieStr]);
81
107
  return /* @__PURE__ */ jsx(TransportProvider, { transport, children });
82
108
  };
109
+ const useGlobalsearchParams = () => {
110
+ const mtapp = useMtmApp();
111
+ return {
112
+ searchParams: mtapp.globalSearchParams,
113
+ setSearchParams: mtapp.setGlobalSearchParams
114
+ };
115
+ };
83
116
  export {
84
117
  GomtmProvider,
85
118
  MtConnectProvider,
119
+ useGlobalsearchParams,
86
120
  useHostname,
87
121
  useMtmApp
88
122
  };