gomtm 0.0.177 → 0.0.179

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.
@@ -26,7 +26,7 @@ import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
26
26
  import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
27
27
  import { callUnaryMethod } from "../connectquery";
28
28
  import { ListViewLayout } from "../gomtmpb/mtm/sppb/mtm_pb";
29
- import { gomtmBaseUrlAtom, transportAtom } from "../store/GomtmBackendProvider";
29
+ import { gomtmBaseUrlAtom, transportAtom } from "../providers/GomtmProvider";
30
30
  import { ListItemView } from "./list-item/ListItem";
31
31
  const curdActivateIdAtom = atom("");
32
32
  const curd3ListParamsAtom = atom({});
@@ -20,7 +20,6 @@ var __async = (__this, __arguments, generator) => {
20
20
  };
21
21
  import { Fragment, jsx } from "react/jsx-runtime";
22
22
  import { MTM_SERVER_COOKIE_ACTIVATE_URL } from "../consts";
23
- import { GomtmBackendProvider } from "../store/GomtmBackendProvider";
24
23
  import { GomtmProvider } from "./GomtmProvider";
25
24
  function GomtmAppSS(props) {
26
25
  return __async(this, null, function* () {
@@ -29,12 +28,7 @@ function GomtmAppSS(props) {
29
28
  if (!backend) {
30
29
  return /* @__PURE__ */ jsx(Fragment, { children: "missing backend" });
31
30
  }
32
- return /* @__PURE__ */ jsx(
33
- GomtmProvider,
34
- {
35
- children: /* @__PURE__ */ jsx(GomtmBackendProvider, { baseUrl: backend, children })
36
- }
37
- );
31
+ return /* @__PURE__ */ jsx(GomtmProvider, { backendUrl: backend, children });
38
32
  });
39
33
  }
40
34
  const ssrGetBackendUrl = () => {
@@ -1,4 +1,5 @@
1
1
  import { Dispatch, PropsWithChildren } from 'react';
2
+ import { Transport } from '@connectrpc/connect';
2
3
  import React from 'react';
3
4
  export declare const mtmAppStore: {
4
5
  get: <Value>(atom: import("jotai").Atom<Value>) => Value;
@@ -43,20 +44,27 @@ export type ActionHandler = (props: {
43
44
  action: string;
44
45
  values?: any;
45
46
  }) => void;
47
+ export declare const gomtmBaseUrlAtom: import("jotai").PrimitiveAtom<string> & {
48
+ init: string;
49
+ };
50
+ export declare const transportAtom: import("jotai").Atom<Transport>;
51
+ export declare const useGomtmBackend: () => {
52
+ gomtmBaseUrl: string;
53
+ };
54
+ interface GomtmAppProps {
55
+ backendUrl?: string | null;
56
+ }
46
57
  interface IAppContext {
47
- extKv: Record<string, any>;
48
58
  token?: string | null;
49
59
  hostname?: string | null;
50
- backendUrl?: string | null;
51
- trpcBackendUrl?: string | null;
52
60
  isDebug?: boolean;
53
61
  debugData?: any;
54
62
  setDebugData: Dispatch<any>;
55
63
  isOpenDebugView?: boolean;
56
64
  setOpenDebugView: Dispatch<React.SetStateAction<boolean>>;
57
65
  }
58
- export declare function GomtmProvider(props: {} & PropsWithChildren): React.JSX.Element;
59
- export declare function useMtmApp(): IAppContext;
66
+ export declare function GomtmProvider(props: {} & GomtmAppProps & PropsWithChildren): React.JSX.Element;
67
+ export declare function useMtmApp(): IAppContext & GomtmAppProps;
60
68
  export declare const useMtmBackendUrl: () => string | null | undefined;
61
69
  export declare const useHostname: () => string;
62
70
  export declare const useExtInfo: () => (key: string) => string | null | undefined;
@@ -64,4 +72,5 @@ export declare const useToken: () => {
64
72
  token: string;
65
73
  setToken: (newToken: string) => void;
66
74
  };
75
+ export declare const MtConnectProvider: (props: PropsWithChildren) => React.JSX.Element;
67
76
  export {};
@@ -1,16 +1,52 @@
1
1
  "use client";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { createContext, useCallback, useContext, useState } from "react";
4
- import { createStore } from "jotai";
4
+ import { createConnectTransport } from "@connectrpc/connect-web";
5
+ import { atom, createStore, useAtom } from "jotai";
5
6
  import { getCookie } from "mtxlib/clientlib";
7
+ import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
8
+ import { isDebugAtom } from "mtxuilib/store/app.atoms";
9
+ import { useHotkeys } from "react-hotkeys-hook";
10
+ import { TransportProvider } from "../connectquery";
6
11
  import { ExtKey_Hostname, ExtKey_SelfBackend, ExtKey_mtmaccessToken, ExtKey_mtmbackend, MtM_TOKEN_NAME } from "../consts";
7
- import { MtConnectProvider } from "./MtConnectProvider";
12
+ import { gomtmFetcher } from "../gomtm-clients-ss";
8
13
  import { MtReactQueryProvider } from "./ReactQueryProvider";
9
14
  const mtmAppStore = createStore();
15
+ const gomtmBaseUrlAtom = atom("");
16
+ const curd3BackendUrlAtom = atom((get) => {
17
+ const value1 = get(gomtmBaseUrlAtom);
18
+ if (value1) {
19
+ return value1;
20
+ }
21
+ if (typeof window == "undefined") {
22
+ console.log("get gomtm backendurl(SSR)", process.env.MTM_BACKEND);
23
+ return process.env.MTM_BACKEND || "";
24
+ }
25
+ return "";
26
+ });
27
+ const transportAtom = atom((get) => {
28
+ const baseUrl = get(curd3BackendUrlAtom);
29
+ return createConnectTransport({
30
+ baseUrl,
31
+ fetch: gomtmFetcher()
32
+ });
33
+ });
34
+ const useGomtmBackend = () => {
35
+ const [gomtmBaseUrl, setgomtmBaseUrl] = useAtom(gomtmBaseUrlAtom);
36
+ return {
37
+ gomtmBaseUrl
38
+ };
39
+ };
10
40
  const AppContext = createContext(void 0);
11
41
  function GomtmProvider(props) {
12
42
  const { children } = props;
13
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsx(MtReactQueryProvider, { children }) }) });
43
+ const [isDebug, setDebug] = useAtom(isDebugAtom);
44
+ useHotkeys("alt+j", () => {
45
+ setDebug(!isDebug);
46
+ }, [isDebug, setDebug]);
47
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(AtomsHydrator, { atomValues: [
48
+ [gomtmBaseUrlAtom, props.backendUrl]
49
+ ], children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsx(MtReactQueryProvider, { children }) }) }) });
14
50
  }
15
51
  function useMtmApp() {
16
52
  const mtappContext = useContext(AppContext);
@@ -63,10 +99,19 @@ const useToken = () => {
63
99
  }
64
100
  };
65
101
  };
102
+ const MtConnectProvider = (props) => {
103
+ const { children } = props;
104
+ const [transport] = useAtom(transportAtom);
105
+ return /* @__PURE__ */ jsx(TransportProvider, { transport, children });
106
+ };
66
107
  export {
67
108
  GomtmProvider,
109
+ MtConnectProvider,
110
+ gomtmBaseUrlAtom,
68
111
  mtmAppStore,
112
+ transportAtom,
69
113
  useExtInfo,
114
+ useGomtmBackend,
70
115
  useHostname,
71
116
  useMtmApp,
72
117
  useMtmBackendUrl,
@@ -0,0 +1,5 @@
1
+ export declare const isAdminAtom: import("jotai").PrimitiveAtom<boolean> & {
2
+ init: boolean;
3
+ };
4
+ export declare const useIsAdmin: () => boolean;
5
+ export declare function isRoleMatch(currentRoles: string[], allowRoles?: string[]): boolean;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { atom, useAtom } from "jotai";
3
+ const isAdminAtom = atom(false);
4
+ const useIsAdmin = () => {
5
+ const [isAdmin, setisAdmin] = useAtom(isAdminAtom);
6
+ return isAdmin;
7
+ };
8
+ function isRoleMatch(currentRoles, allowRoles) {
9
+ if (!currentRoles) {
10
+ return true;
11
+ }
12
+ if (!(allowRoles == null ? void 0 : allowRoles.length)) {
13
+ return true;
14
+ }
15
+ for (const roleName of allowRoles) {
16
+ const ok = currentRoles.find((x) => x == roleName);
17
+ if (ok) {
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ }
23
+ export {
24
+ isAdminAtom,
25
+ isRoleMatch,
26
+ useIsAdmin
27
+ };