gomtm 0.0.286 → 0.0.288

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.
@@ -1,5 +1,4 @@
1
1
  export declare const COOKIE_MTM_SITE_ID = "mtm-site-id";
2
- export declare const COOKIE_IS_DEBUG = "DEBUG";
3
2
  export declare const MTM_SITE_HOSTNAME = "mtm-site-hostname";
4
3
  export declare const MtM_TOKEN_NAME = "mtmToken";
5
4
  export declare const fetchMaxRetry = 3;
@@ -11,7 +10,6 @@ export declare const MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL = "mtm:selfbacke
11
10
  export declare const DEFAULT_revalidate_SECONDS = 3;
12
11
  export declare const LOGIN_CALLBACK_URL_KEY = "back";
13
12
  export declare const MTM_API_PREFIX = "/api";
14
- export declare const LayoutNameCookie = "layout";
15
13
  export declare const IsDebugCookie = "is_debug";
16
14
  export declare const ExtKey_Hostname = "host";
17
15
  export declare const ItemAction_list_new_item = "list_new_item";
@@ -31,3 +29,22 @@ export declare const HOTKEY_Switchlayout = "alt+l";
31
29
  export declare const HOTKEY_Listview_Switchlayout = "alt+m";
32
30
  export declare const HOTKEY_ListViewCMDK = "alt+c";
33
31
  export declare const CONST_debounce_INPUT = 300;
32
+ export declare const gomtmAppConfig: {
33
+ cookieBackendUrl: string;
34
+ cookieListViewLayout: string;
35
+ CookieLayout: string;
36
+ CookieConfigState: string;
37
+ };
38
+ export declare const getGomtmConfig: () => {
39
+ cookieBackendUrl: string;
40
+ cookieListViewLayout: string;
41
+ CookieLayout: string;
42
+ CookieConfigState: string;
43
+ };
44
+ export interface ConfigState {
45
+ debug?: boolean;
46
+ theme?: string;
47
+ layout?: string;
48
+ listviewLayout?: string;
49
+ }
50
+ export declare const configState: ConfigState;
@@ -1,5 +1,4 @@
1
1
  const COOKIE_MTM_SITE_ID = "mtm-site-id";
2
- const COOKIE_IS_DEBUG = "DEBUG";
3
2
  const MTM_SITE_HOSTNAME = "mtm-site-hostname";
4
3
  const MtM_TOKEN_NAME = "mtmToken";
5
4
  const fetchMaxRetry = 3;
@@ -11,7 +10,6 @@ const MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL = "mtm:selfbackendUrl";
11
10
  const DEFAULT_revalidate_SECONDS = 3;
12
11
  const LOGIN_CALLBACK_URL_KEY = "back";
13
12
  const MTM_API_PREFIX = "/api";
14
- const LayoutNameCookie = "layout";
15
13
  const IsDebugCookie = "is_debug";
16
14
  const ExtKey_Hostname = "host";
17
15
  const ItemAction_list_new_item = "list_new_item";
@@ -31,6 +29,21 @@ const HOTKEY_Switchlayout = "alt+l";
31
29
  const HOTKEY_Listview_Switchlayout = "alt+m";
32
30
  const HOTKEY_ListViewCMDK = "alt+c";
33
31
  const CONST_debounce_INPUT = 300;
32
+ const gomtmAppConfig = {
33
+ cookieBackendUrl: "backendUrl",
34
+ cookieListViewLayout: "listViewLayout",
35
+ CookieLayout: "layout",
36
+ CookieConfigState: "_config"
37
+ };
38
+ const getGomtmConfig = () => {
39
+ return gomtmAppConfig;
40
+ };
41
+ const configState = {
42
+ debug: false,
43
+ theme: "",
44
+ layout: "",
45
+ listviewLayout: ""
46
+ };
34
47
  export {
35
48
  ADMIN_ROLE,
36
49
  ActionCreate,
@@ -39,7 +52,6 @@ export {
39
52
  ActionFetchNextPage,
40
53
  ActionRefetch,
41
54
  CONST_debounce_INPUT,
42
- COOKIE_IS_DEBUG,
43
55
  COOKIE_MTM_SITE_ID,
44
56
  Cookie_Site_Host,
45
57
  DEFAULT_revalidate_SECONDS,
@@ -54,7 +66,6 @@ export {
54
66
  IsDebugCookie,
55
67
  ItemAction_list_new_item,
56
68
  LOGIN_CALLBACK_URL_KEY,
57
- LayoutNameCookie,
58
69
  ListView_DefaultPageSize,
59
70
  Listview_list_filter,
60
71
  MEMBER_ROLE,
@@ -64,5 +75,8 @@ export {
64
75
  MTM_SITE_HOSTNAME,
65
76
  MtM_TOKEN_NAME,
66
77
  TRPC_API_PREFIX,
67
- fetchMaxRetry
78
+ configState,
79
+ fetchMaxRetry,
80
+ getGomtmConfig,
81
+ gomtmAppConfig
68
82
  };
@@ -1,5 +1,7 @@
1
1
  import { Message } from "@bufbuild/protobuf";
2
2
  import { Dispatch, PropsWithChildren, SetStateAction } from "react";
3
+ export declare const LzListViewLayoutDemo: import("react").LazyExoticComponent<typeof import("./listview-layouts/listviewlayout-demo").default>;
4
+ export declare const LzListViewLayoutDefault: import("react").LazyExoticComponent<typeof import("./listview-layouts/default").default>;
3
5
  interface ListViewProps {
4
6
  svc: string;
5
7
  methodList: string;
@@ -37,7 +39,7 @@ export declare function useListView<I extends Message<I>, O extends Message<O>>(
37
39
  setOpenDebug?: Dispatch<SetStateAction<boolean>> | undefined;
38
40
  setParams?: Dispatch<any> | undefined;
39
41
  setDetailData?: Dispatch<any> | undefined;
40
- setLayout?: Dispatch<SetStateAction<string>> | undefined;
42
+ setLayout?: ((arg0: string) => void) | undefined;
41
43
  };
42
44
  export declare function useDetail(): {
43
45
  svc: string;
@@ -62,7 +64,7 @@ export declare function useDetail(): {
62
64
  setOpenDebug: Dispatch<SetStateAction<boolean>>;
63
65
  setParams: Dispatch<any>;
64
66
  setDetailData: Dispatch<any>;
65
- setLayout: Dispatch<SetStateAction<string>>;
67
+ setLayout: (arg0: string) => void;
66
68
  };
67
69
  export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
68
70
  export declare const ListViewActions: () => import("react").JSX.Element;
@@ -46,7 +46,7 @@ import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
46
46
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
47
47
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
48
48
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
49
- import { Suspense, createContext, useCallback, useContext, useMemo, useState } from "react";
49
+ import { Suspense, createContext, lazy, useCallback, useContext, useMemo, useState } from "react";
50
50
  import { useHotkeys } from "react-hotkeys-hook";
51
51
  import { MtmErrorView } from "../../components/MtmErrorView";
52
52
  import { CONST_debounce_INPUT, HOTKEY_Listview_Switchlayout } from "../../consts";
@@ -56,16 +56,16 @@ import CurdCreatePanel, { CurdCreatePanelTriggerButton } from "../create/CurdCre
56
56
  import CurdEditPanel, { CurdEditPanelTriggerButton } from "../edit/CurdEditPanel";
57
57
  import { ListItemView } from "../list-item/ListItem";
58
58
  import { ListLayout } from "../list-item/ListLayout";
59
- import { ListViewLayoutDefault } from "./listview-layouts/default";
60
- import ListViewLayoutDemo from "./listview-layouts/listviewlayout-demo";
61
59
  const ALL_Layouts = [
62
60
  "default",
63
61
  "demo"
64
62
  ];
63
+ const LzListViewLayoutDemo = lazy(() => import("./listview-layouts/listviewlayout-demo"));
64
+ const LzListViewLayoutDefault = lazy(() => import("./listview-layouts/default"));
65
65
  const commonListViewContext = createContext(void 0);
66
66
  function ListViewProvider(props) {
67
67
  var _a;
68
- const { children, svc, methodList, methodDelete, slugPath, methodCreate, methodGet, params } = props;
68
+ const { children, svc, methodList, methodDelete, slugPath, methodCreate, methodGet, params, layout } = props;
69
69
  const mtapp = useMtmApp();
70
70
  const [_svc, setSvc] = useState(svc);
71
71
  const [openRemove, setOpenRemove] = useState(false);
@@ -75,7 +75,7 @@ function ListViewProvider(props) {
75
75
  const [openDebug, setOpenDebug] = useState(false);
76
76
  const [_params, _setParams] = useState(params);
77
77
  const [detailData, setDetailData] = useState(void 0);
78
- const [layout, setLayout] = useState("default");
78
+ const [_layout, _setLayout] = useState(mtapp.listviewLayout);
79
79
  const __params = useMemo(() => {
80
80
  var _a2, _b;
81
81
  return __spreadProps(__spreadValues({}, params), {
@@ -87,6 +87,10 @@ function ListViewProvider(props) {
87
87
  const setParams = useCallback(debounce((values) => {
88
88
  _setParams(values);
89
89
  }, CONST_debounce_INPUT), [_setParams]);
90
+ const setLayout = useCallback((name) => {
91
+ _setLayout(name);
92
+ mtapp.setListViewLayout(name);
93
+ }, [mtapp]);
90
94
  return /* @__PURE__ */ jsx(commonListViewContext.Provider, { value: {
91
95
  svc: _svc,
92
96
  methodList,
@@ -108,7 +112,7 @@ function ListViewProvider(props) {
108
112
  setParams,
109
113
  detailData,
110
114
  setDetailData,
111
- layout,
115
+ layout: _layout,
112
116
  setLayout
113
117
  }, children: /* @__PURE__ */ jsxs(ListViewLayout, { children: [
114
118
  " ",
@@ -213,9 +217,9 @@ const ListViewLayout = (props) => {
213
217
  const Layout = useMemo(() => {
214
218
  switch (listView.layout) {
215
219
  case "demo":
216
- return ListViewLayoutDemo;
220
+ return LzListViewLayoutDemo;
217
221
  default:
218
- return ListViewLayoutDefault;
222
+ return LzListViewLayoutDefault;
219
223
  }
220
224
  }, [listView.layout]);
221
225
  return /* @__PURE__ */ jsx(Layout, { children });
@@ -243,6 +247,8 @@ export {
243
247
  CommonListView,
244
248
  ListViewActions,
245
249
  ListViewProvider,
250
+ LzListViewLayoutDefault,
251
+ LzListViewLayoutDemo,
246
252
  useDetail,
247
253
  useListView
248
254
  };
@@ -1,2 +1,2 @@
1
1
  import { PropsWithChildren } from "react";
2
- export declare const ListViewLayoutDefault: (props: PropsWithChildren) => import("react").JSX.Element;
2
+ export default function ListViewLayoutDefault(props: PropsWithChildren): import("react").JSX.Element;
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
- const ListViewLayoutDefault = (props) => {
3
+ function ListViewLayoutDefault(props) {
4
4
  const { children } = props;
5
5
  return /* @__PURE__ */ jsx(Fragment, { children });
6
- };
6
+ }
7
7
  export {
8
- ListViewLayoutDefault
8
+ ListViewLayoutDefault as default
9
9
  };
@@ -69,7 +69,7 @@ const LayoutSwitchDlg = () => {
69
69
  ] }),
70
70
  /* @__PURE__ */ jsx("div", { className: "flex gap-2 bg-red-100 p-2", children: ALL_Layouts.map((layout) => {
71
71
  return /* @__PURE__ */ jsx(MtButton, { onClick: () => {
72
- mtapp.setLayoutName(layout);
72
+ mtapp.setLayout(layout);
73
73
  setOpen(false);
74
74
  }, children: layout }, layout);
75
75
  }) })
@@ -20,20 +20,27 @@ var __async = (__this, __arguments, generator) => {
20
20
  };
21
21
  import { Fragment, jsx } from "react/jsx-runtime";
22
22
  import { cookies, headers } from "next/headers";
23
- import { IsDebugCookie, LayoutNameCookie } from "../consts";
23
+ import { IsDebugCookie, getGomtmConfig } from "../consts";
24
24
  import { ssrGetBackendUrl } from "../mtmFetcher";
25
25
  import { GomtmProvider } from "./GomtmProvider";
26
26
  function GomtmAppSS(props) {
27
27
  return __async(this, null, function* () {
28
- var _a, _b;
28
+ var _a, _b, _c, _d;
29
29
  const { children } = props;
30
- const backend = ssrGetBackendUrl();
30
+ const gomtmAppConfig = getGomtmConfig();
31
+ let backend = ssrGetBackendUrl();
32
+ const backendFromCookie = (_a = cookies().get(gomtmAppConfig.cookieBackendUrl)) == null ? void 0 : _a.value;
33
+ if (backendFromCookie) {
34
+ backend = backendFromCookie;
35
+ }
31
36
  if (!backend) {
32
37
  return /* @__PURE__ */ jsx(Fragment, { children: "missing backend" });
33
38
  }
34
39
  const cookiesStr = headers().get("Cookie");
35
- const layoutName = (_a = cookies().get(LayoutNameCookie)) == null ? void 0 : _a.value;
36
- const isDebug = !!((_b = cookies().get(IsDebugCookie)) == null ? void 0 : _b.value);
40
+ const layoutName = (_b = cookies().get(gomtmAppConfig.CookieLayout)) == null ? void 0 : _b.value;
41
+ const isDebug = !!((_c = cookies().get(IsDebugCookie)) == null ? void 0 : _c.value);
42
+ const configStateJson = ((_d = cookies().get(gomtmAppConfig.CookieConfigState)) == null ? void 0 : _d.value) || "{}";
43
+ const configState = JSON.parse(configStateJson);
37
44
  return /* @__PURE__ */ jsx(
38
45
  GomtmProvider,
39
46
  {
@@ -41,6 +48,8 @@ function GomtmAppSS(props) {
41
48
  isDebug,
42
49
  layoutName,
43
50
  cookieStr: cookiesStr || "",
51
+ config: gomtmAppConfig,
52
+ configState,
44
53
  children
45
54
  }
46
55
  );
@@ -1,26 +1,46 @@
1
1
  import { Dispatch, PropsWithChildren, SetStateAction } from 'react';
2
+ import { ConfigState, getGomtmConfig } from '../consts';
2
3
  export type ActionHandler = (props: {
3
4
  action: string;
4
5
  values?: any;
5
6
  }) => void;
6
7
  interface GomtmAppProps {
8
+ config: ReturnType<typeof getGomtmConfig>;
9
+ configState: ConfigState;
7
10
  backendUrl?: string | null;
8
11
  isDebug?: boolean;
9
12
  layoutName?: string;
13
+ listviewLayout?: string;
10
14
  cookieStr?: string;
11
15
  }
12
16
  export declare function GomtmProvider(props: {} & GomtmAppProps & PropsWithChildren): import("react").JSX.Element;
13
17
  export declare function useMtmApp(): {
14
18
  hostname?: string | null | undefined;
15
- setIsDebug: Dispatch<SetStateAction<boolean>>;
19
+ setDebug: (arg0: boolean) => void;
16
20
  setBackendUrl: Dispatch<SetStateAction<string | null | undefined>>;
17
- setLayoutName: Dispatch<SetStateAction<string>>;
21
+ setLayout: (arg0: string) => void;
22
+ setListViewLayout: (arg0: string) => void;
18
23
  setCookieStr: Dispatch<SetStateAction<string>>;
19
24
  globalSearchParams?: any;
20
25
  setGlobalSearchParams: Dispatch<any>;
26
+ setConfig: Dispatch<SetStateAction<{
27
+ cookieBackendUrl: string;
28
+ cookieListViewLayout: string;
29
+ CookieLayout: string;
30
+ CookieConfigState: string;
31
+ }>>;
32
+ setConfigState: Dispatch<SetStateAction<ConfigState>>;
33
+ config: {
34
+ cookieBackendUrl: string;
35
+ cookieListViewLayout: string;
36
+ CookieLayout: string;
37
+ CookieConfigState: string;
38
+ };
39
+ configState: ConfigState;
21
40
  backendUrl?: string | null | undefined;
22
41
  isDebug?: boolean | undefined;
23
42
  layoutName?: string | undefined;
43
+ listviewLayout?: string | undefined;
24
44
  cookieStr?: string | undefined;
25
45
  };
26
46
  export declare const useHostname: () => string;
@@ -19,26 +19,26 @@ import { jsx, jsxs } from "react/jsx-runtime";
19
19
  import { createContext, useCallback, useContext, useMemo, useState } from "react";
20
20
  import { createConnectTransport } from "@connectrpc/connect-web";
21
21
  import { debounce } from "lodash";
22
+ import { setCookie } from "mtxlib/clientlib";
22
23
  import { useSearchParams } from "next/navigation";
23
24
  import { useHotkeys } from "react-hotkeys-hook";
24
25
  import { GoMtmDebug } from "../components/devtools/GoMtmDebug";
25
26
  import { TransportProvider } from "../connectquery";
26
- import { HOTKEY_Debug } from "../consts";
27
+ import { HOTKEY_Debug, IsDebugCookie, getGomtmConfig } from "../consts";
27
28
  import { anypbTypeReg } from "../messageTypeRegistry";
28
29
  import { gomtmFetcher } from "../mtmFetcher";
29
30
  import { MtReactQueryProvider } from "./ReactQueryProvider";
30
31
  const AppContext = createContext(void 0);
31
32
  function GomtmProvider(props) {
32
- const { backendUrl, children } = props;
33
- const [_isDebug, setDebug] = useState(false);
33
+ const { backendUrl, layoutName, isDebug, children, listviewLayout, config, configState } = props;
34
+ const [_config, setConfig] = useState(config);
35
+ const [_configState, _setConfigState] = useState(configState);
36
+ const [_isDebug, _setDebug] = useState(isDebug || false);
34
37
  const [_backendUrl, setBackendUrl] = useState(backendUrl);
35
- const [_layoutName, setLayoutName] = useState("front");
36
- const [openLayoutSwitchDlg, setOpenLayoutSwitchDlg] = useState(false);
38
+ const [_layoutName, setLayoutName] = useState(layoutName);
39
+ const [_listviewLayout, _setListViewLayout] = useState(listviewLayout);
37
40
  const [_cookieStr, setCookieStr] = useState("");
38
41
  const [_globalSearchParams, _setGlobalSearchParams] = useState({});
39
- useHotkeys(HOTKEY_Debug, () => {
40
- setDebug((pre) => !pre);
41
- }, [_isDebug, setDebug]);
42
42
  const searchParams = useSearchParams();
43
43
  const setGlobalSearchParams = useCallback(debounce((values) => {
44
44
  _setGlobalSearchParams(values);
@@ -47,15 +47,34 @@ function GomtmProvider(props) {
47
47
  const q = searchParams.get("q");
48
48
  return __spreadValues({ q }, _globalSearchParams);
49
49
  }, [searchParams, _globalSearchParams]);
50
+ const setLayout = useCallback((name) => {
51
+ setLayoutName(name);
52
+ setCookie(config == null ? void 0 : config.CookieLayout, name);
53
+ }, [config == null ? void 0 : config.CookieLayout]);
54
+ const setListViewLayout = useCallback((name) => {
55
+ setLayoutName(name);
56
+ setCookie(getGomtmConfig().cookieListViewLayout, name);
57
+ }, []);
58
+ const setDebug = useCallback((debug) => {
59
+ _setDebug(debug);
60
+ setCookie(IsDebugCookie, debug);
61
+ }, []);
62
+ useHotkeys(HOTKEY_Debug, () => {
63
+ setDebug(!_isDebug);
64
+ }, [_isDebug, setDebug]);
50
65
  return /* @__PURE__ */ jsx(AppContext.Provider, { value: {
66
+ config,
67
+ setConfig,
68
+ configState: _configState,
69
+ setConfigState: _setConfigState,
51
70
  isDebug: _isDebug,
52
- setIsDebug: setDebug,
71
+ setDebug,
53
72
  backendUrl,
54
73
  setBackendUrl,
55
74
  layoutName: _layoutName,
56
- setLayoutName,
57
- // openLayoutSwitchDlg: openLayoutSwitchDlg,
58
- // setOpenLayoutSwitchDlg: setOpenLayoutSwitchDlg,
75
+ setLayout,
76
+ setListViewLayout,
77
+ listviewLayout,
59
78
  cookieStr: _cookieStr,
60
79
  setCookieStr,
61
80
  globalSearchParams,