gomtm 0.0.223 → 0.0.225

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.
@@ -10,6 +10,7 @@ export declare const MTM_SERVER_COOKIE_ACTIVATE_URL = "mtm:serverUrl";
10
10
  export declare const MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL = "mtm:selfbackendUrl";
11
11
  export declare const DEFAULT_revalidate_SECONDS = 3;
12
12
  export declare const LOGIN_CALLBACK_URL_KEY = "back";
13
+ export declare const MTM_API_PREFIX = "/api";
13
14
  export declare const ExtKey_Hostname = "host";
14
15
  export declare const ExtKey_mtmaccessToken = "access_token";
15
16
  export declare const ItemAction_list_new_item = "list_new_item";
@@ -10,6 +10,7 @@ const MTM_SERVER_COOKIE_ACTIVATE_URL = "mtm:serverUrl";
10
10
  const MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL = "mtm:selfbackendUrl";
11
11
  const DEFAULT_revalidate_SECONDS = 3;
12
12
  const LOGIN_CALLBACK_URL_KEY = "back";
13
+ const MTM_API_PREFIX = "/api";
13
14
  const ExtKey_Hostname = "host";
14
15
  const ExtKey_mtmaccessToken = "access_token";
15
16
  const ItemAction_list_new_item = "list_new_item";
@@ -45,6 +46,7 @@ export {
45
46
  ListView_DefaultPageSize,
46
47
  Listview_list_filter,
47
48
  MEMBER_ROLE,
49
+ MTM_API_PREFIX,
48
50
  MTM_SERVER_COOKIE_ACTIVATE_SELFBACKEND_URL,
49
51
  MTM_SERVER_COOKIE_ACTIVATE_URL,
50
52
  MTM_SITE_HOSTNAME,
@@ -13,3 +13,4 @@ export declare function CommonListViewProvider<I extends Message<I>, O extends M
13
13
  slugPath?: string;
14
14
  } & PropsWithChildren): import("react").JSX.Element;
15
15
  export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
16
+ export declare const ListViewActions: () => import("react").JSX.Element;
@@ -23,8 +23,10 @@ import { jsx, jsxs } from "react/jsx-runtime";
23
23
  import { atom, useAtom } from "jotai";
24
24
  import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
25
25
  import { DebugAtomValue } from "mtxuilib/common/devtools/DebugAtomValue";
26
+ import { Icons } from "mtxuilib/icons/icons";
26
27
  import { cn } from "mtxuilib/lib/utils";
27
28
  import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
29
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
28
30
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
29
31
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
30
32
  import { Suspense } from "react";
@@ -113,18 +115,7 @@ function CommonListView() {
113
115
  /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
114
116
  /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
115
117
  ] }) }),
116
- /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1" }),
117
- /* @__PURE__ */ jsxs(Suspense, { children: [
118
- /* @__PURE__ */ jsx(PanelRemove, {}),
119
- /* @__PURE__ */ jsx(PanelCreate, {}),
120
- /* @__PURE__ */ jsx(DlgCurdDebugInfo, {}),
121
- /* @__PURE__ */ jsx(CurdCreatePanel, {}),
122
- /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 p-2", children: [
123
- /* @__PURE__ */ jsx(DlgCurdDebugInfoTriggerButton, {}),
124
- /* @__PURE__ */ jsx(CurdEditPanelTriggerButton, {}),
125
- /* @__PURE__ */ jsx(CurdCreatePanelTriggerButton, {})
126
- ] })
127
- ] })
118
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1", children: /* @__PURE__ */ jsx(ListViewActions, {}) })
128
119
  ] });
129
120
  }
130
121
  const PanelRemove = () => {
@@ -156,9 +147,31 @@ const PanelCreate = () => {
156
147
  }), children: "ok" })
157
148
  ] }) });
158
149
  };
150
+ const ListViewActions = () => {
151
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
152
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { variant: "ghost", className: "m-0 flex h-10 w-10 items-center justify-center border p-0 shadow-sm backdrop-blur", children: /* @__PURE__ */ jsx(Icons.ellipsis, {}) }) }),
153
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { className: "w-56", children: [
154
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Edit" }),
155
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
156
+ /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
157
+ /* @__PURE__ */ jsx(PanelRemove, {}),
158
+ /* @__PURE__ */ jsx(PanelCreate, {}),
159
+ /* @__PURE__ */ jsx(DlgCurdDebugInfo, {}),
160
+ /* @__PURE__ */ jsx(CurdCreatePanel, {}),
161
+ /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 p-2", children: [
162
+ /* @__PURE__ */ jsx(DlgCurdDebugInfoTriggerButton, {}),
163
+ /* @__PURE__ */ jsx(CurdEditPanelTriggerButton, {}),
164
+ /* @__PURE__ */ jsx(CurdCreatePanelTriggerButton, {})
165
+ ] })
166
+ ] }) }) }),
167
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
168
+ ] })
169
+ ] });
170
+ };
159
171
  export {
160
172
  CommonListView,
161
173
  CommonListViewProvider,
174
+ ListViewActions,
162
175
  curdSlugPathAtom,
163
176
  exampleListItemComponent,
164
177
  exampleListItemValueComponent
@@ -5,7 +5,7 @@ import { DebugAtomValue } from "mtxuilib/common/devtools/DebugAtomValue";
5
5
  import { flexRender } from "mtxuilib/lib/render";
6
6
  import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
7
7
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
8
- import { isDebugAtom } from "../../store/gomtm.atom";
8
+ import { isDebugAtom } from "../../providers/GomtmProvider";
9
9
  import { exampleListItemComponent } from "../CommonListViewV2";
10
10
  import { createMethodSigAtom, curdActivateIdAtom, removeMethodSigAtom } from "../curd.atoms";
11
11
  const openDlgCurdDebugInfoAtom = atom(false);
@@ -30,7 +30,7 @@ const DlgCurdDebugInfoTriggerButton = () => {
30
30
  }
31
31
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MtButton, { onClick: () => {
32
32
  setOpenDlgCurdDebugInfo(true);
33
- }, children: "DlgCurdDebugInfoTriggerButton" }) });
33
+ }, children: "DlgCurdDebug" }) });
34
34
  };
35
35
  export {
36
36
  DlgCurdDebugInfo,
@@ -1,4 +1,5 @@
1
1
  import { ServiceType } from "@bufbuild/protobuf";
2
+ export declare const ssrGetBackendUrl: () => string;
2
3
  export declare function createMtmServiceClient<T extends ServiceType>(service: T, url?: string): import("@connectrpc/connect").PromiseClient<T>;
3
4
  export declare function createMtmServiceClientByName<T extends ServiceType>(svcName: string, url?: string): import("@connectrpc/connect").PromiseClient<ServiceType>;
4
5
  type CustomRequestInit = RequestInit & {
@@ -37,17 +37,28 @@ var __async = (__this, __arguments, generator) => {
37
37
  import { createPromiseClient } from "@connectrpc/connect";
38
38
  import { createConnectTransport } from "@connectrpc/connect-web";
39
39
  import { merge } from "lodash";
40
+ import { MTM_API_PREFIX } from "./consts";
40
41
  import { MtmService } from "./gomtmpb/mtm/sppb/mtm_connect";
41
- function createMtmServiceClient(service, url) {
42
- const baseUrl = url || process.env.MTM_BACKEND;
43
- if (!baseUrl) {
44
- throw new Error("missing mtm api url,\xB7MTM_BACKEND\xB7");
42
+ const ssrGetBackendUrl = () => {
43
+ var _a;
44
+ if (typeof window == "undefined") {
45
+ if ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.MTM_BACKEND) {
46
+ return process.env.MTM_BACKEND;
47
+ }
48
+ if (process.env.VERCEL_URL) {
49
+ return `https://${process.env.VERCEL_URL}`;
50
+ }
45
51
  }
46
- console.info("gomtm baseUrl:", baseUrl);
52
+ return "";
53
+ };
54
+ function createMtmServiceClient(service, url) {
55
+ const baseUrl = ssrGetBackendUrl();
56
+ const apiUrl = new URL(MTM_API_PREFIX, baseUrl).toString();
57
+ console.info("gomtm apiUrl:", baseUrl);
47
58
  return createPromiseClient(
48
59
  service,
49
60
  createConnectTransport({
50
- baseUrl,
61
+ baseUrl: apiUrl,
51
62
  fetch: gomtmFetcher()
52
63
  })
53
64
  );
@@ -125,5 +136,6 @@ const gomtmFetcher = (initGlobal) => {
125
136
  export {
126
137
  createMtmServiceClient,
127
138
  createMtmServiceClientByName,
128
- gomtmFetcher
139
+ gomtmFetcher,
140
+ ssrGetBackendUrl
129
141
  };
@@ -1,3 +1,2 @@
1
1
  import { PropsWithChildren } from "react";
2
2
  export declare function GomtmAppSS(props: {} & PropsWithChildren): Promise<import("react").JSX.Element>;
3
- export declare const ssrGetBackendUrl: () => string;
@@ -19,7 +19,10 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
  import { Fragment, jsx } from "react/jsx-runtime";
22
- import { GomtmProvider } from "./GomtmProvider";
22
+ import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
23
+ import { headers } from "next/headers";
24
+ import { GomtmProvider, cookiesAtom } from "./GomtmProvider";
25
+ import { ssrGetBackendUrl } from "../mtmFetcher";
23
26
  function GomtmAppSS(props) {
24
27
  return __async(this, null, function* () {
25
28
  const { children } = props;
@@ -27,22 +30,12 @@ function GomtmAppSS(props) {
27
30
  if (!backend) {
28
31
  return /* @__PURE__ */ jsx(Fragment, { children: "missing backend" });
29
32
  }
30
- return /* @__PURE__ */ jsx(GomtmProvider, { backendUrl: backend, children });
33
+ const cookiesStr = headers().get("Cookie");
34
+ return /* @__PURE__ */ jsx(GomtmProvider, { backendUrl: backend, children: /* @__PURE__ */ jsx(ScopeAtomsHydrator, { atomValues: [
35
+ [cookiesAtom, cookiesStr]
36
+ ], children }) });
31
37
  });
32
38
  }
33
- const ssrGetBackendUrl = () => {
34
- var _a;
35
- if (typeof window == "undefined") {
36
- if ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.MTM_BACKEND) {
37
- return process.env.MTM_BACKEND;
38
- }
39
- if (process.env.VERCEL_URL) {
40
- return `https://${process.env.VERCEL_URL}`;
41
- }
42
- }
43
- return "https://localhost";
44
- };
45
39
  export {
46
- GomtmAppSS,
47
- ssrGetBackendUrl
40
+ GomtmAppSS
48
41
  };
@@ -46,14 +46,12 @@ export type ActionHandler = (props: {
46
46
  export declare const gomtmBaseUrlAtom: import("jotai").PrimitiveAtom<string> & {
47
47
  init: string;
48
48
  };
49
- export declare const cookiesValueAtom: import("jotai").PrimitiveAtom<string | undefined> & {
50
- init: string | undefined;
49
+ export declare const cookiesAtom: import("jotai").WritableAtom<string | undefined, [value: string], void>;
50
+ export declare const isDebugValueAtom: import("jotai").PrimitiveAtom<boolean> & {
51
+ init: boolean;
51
52
  };
52
- export declare const cookiesAtom: import("jotai").Atom<string | undefined>;
53
+ export declare const isDebugAtom: import("jotai").WritableAtom<boolean, [value: boolean], void>;
53
54
  export declare const transportAtom: import("jotai").Atom<Transport>;
54
- export declare const useGomtmBackend: () => {
55
- gomtmBaseUrl: string;
56
- };
57
55
  interface GomtmAppProps {
58
56
  backendUrl?: string | null;
59
57
  }
@@ -7,7 +7,6 @@ import { AtomsHydrator } from "mtxlib/jotai/jotai-helper";
7
7
  import { useHotkeys } from "react-hotkeys-hook";
8
8
  import { TransportProvider } from "../connectquery";
9
9
  import { gomtmFetcher } from "../mtmFetcher";
10
- import { isDebugAtom } from "../store/gomtm.atom";
11
10
  import { MtReactQueryProvider } from "./ReactQueryProvider";
12
11
  const mtmAppStore = createStore();
13
12
  const gomtmBaseUrlAtom = atom("");
@@ -26,28 +25,25 @@ const cookiesValueAtom = atom(void 0);
26
25
  const cookiesAtom = atom((get) => {
27
26
  const v = get(cookiesValueAtom);
28
27
  return v;
28
+ }, (_, set, value) => {
29
+ set(cookiesValueAtom, value);
30
+ });
31
+ const isDebugValueAtom = atom(false);
32
+ const isDebugAtom = atom((get) => {
33
+ return get(isDebugValueAtom);
34
+ }, (_, set, value) => {
35
+ set(isDebugValueAtom, value);
29
36
  });
30
37
  const transportAtom = atom((get) => {
31
38
  const baseUrl = get(curd3BackendUrlAtom);
32
- const baseUrl2 = new URL("/api", baseUrl).toString();
33
39
  const cookiesStr = get(cookiesAtom);
34
- console.log("transportAtom :", {
35
- baseUrl2,
36
- cookiesStr
37
- });
38
40
  return createConnectTransport({
39
- baseUrl: baseUrl2,
41
+ baseUrl,
40
42
  fetch: gomtmFetcher({
41
43
  cookieStr: cookiesStr
42
44
  })
43
45
  });
44
46
  });
45
- const useGomtmBackend = () => {
46
- const [gomtmBaseUrl, setgomtmBaseUrl] = useAtom(gomtmBaseUrlAtom);
47
- return {
48
- gomtmBaseUrl
49
- };
50
- };
51
47
  const AppContext = createContext(void 0);
52
48
  function GomtmProvider(props) {
53
49
  const { children } = props;
@@ -88,11 +84,11 @@ export {
88
84
  GomtmProvider,
89
85
  MtConnectProvider,
90
86
  cookiesAtom,
91
- cookiesValueAtom,
92
87
  gomtmBaseUrlAtom,
88
+ isDebugAtom,
89
+ isDebugValueAtom,
93
90
  mtmAppStore,
94
91
  transportAtom,
95
- useGomtmBackend,
96
92
  useHostname,
97
93
  useMtmApp,
98
94
  useMtmBackendUrl
@@ -1,7 +1,3 @@
1
- export declare const isAdminAtom: import("jotai").PrimitiveAtom<boolean> & {
2
- init: boolean;
3
- };
4
- export declare const useIsAdmin: () => boolean;
5
1
  export declare function isRoleMatch(currentRoles: string[], allowRoles?: string[]): boolean;
6
2
  import { MyJWTPayload } from "../lib/auth/jwt";
7
3
  export declare function useAuth(): {
@@ -1,10 +1,4 @@
1
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
2
  function isRoleMatch(currentRoles, allowRoles) {
9
3
  if (!currentRoles) {
10
4
  return true;
@@ -36,8 +30,6 @@ function useAuth() {
36
30
  return { auth, userId, isAdmin };
37
31
  }
38
32
  export {
39
- isAdminAtom,
40
33
  isRoleMatch,
41
- useAuth,
42
- useIsAdmin
34
+ useAuth
43
35
  };