gomtm 0.0.254 → 0.0.256

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,11 +1,19 @@
1
1
  import type { Message, PartialMessage } from "@bufbuild/protobuf";
2
- import { PropsWithChildren } from "react";
2
+ import { Dispatch, PropsWithChildren } from "react";
3
3
  import { MethodUnaryDescriptor } from "../connectquery";
4
- export declare const curdDetailPageDataAtom: import("jotai").PrimitiveAtom<undefined> & {
5
- init: undefined;
4
+ interface CurdDetailProps {
5
+ curdDetailPageData?: any | null;
6
+ methodGet: MethodUnaryDescriptor<any, any>;
7
+ params?: PartialMessage<any>;
8
+ }
9
+ export declare function CurdDetailProvider<I extends Message<I>, O extends Message<O>>(props: CurdDetailProps & PropsWithChildren): import("react").JSX.Element;
10
+ export declare function useDetail(): {
11
+ setCurdDetailPageData: Dispatch<any>;
12
+ curdDetailPageData?: any;
13
+ methodGet: MethodUnaryDescriptor<any, any>;
14
+ params?: PartialMessage<any> | undefined;
6
15
  };
7
- export declare function CurdDetailProvider<I extends Message<I>, O extends Message<O>>(props: {
8
- methodGet: MethodUnaryDescriptor<I, O>;
9
- params?: PartialMessage<I>;
10
- } & PropsWithChildren): import("react").JSX.Element;
11
16
  export declare const DetailViewDataDlg: () => import("react").JSX.Element;
17
+ export declare function DlgCurdDebugInfo(): import("react").JSX.Element;
18
+ export declare const DlgCurdDebugInfoTriggerButton: () => import("react").JSX.Element | null;
19
+ export {};
@@ -1,33 +1,75 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { atom, useAtom } from "jotai";
4
- import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
5
- import { Dialog, DialogContent, DialogTrigger } from "mtxuilib/ui/dialog";
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 { Dialog, DialogContent, DialogTitle, DialogTrigger } from "mtxuilib/ui/dialog";
6
20
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
7
- import { Suspense } from "react";
21
+ import { Suspense, createContext, useContext, useState } from "react";
8
22
  import { useSuspenseQuery } from "../connectquery";
9
23
  import { useMtmApp } from "../providers/GomtmProvider";
10
- const curdDetailPageDataAtom = atom(void 0);
24
+ import { useListView } from "./ListViewProvider";
25
+ const CurdDetailContext = createContext(void 0);
11
26
  function CurdDetailProvider(props) {
12
- const { children, methodGet, params } = props;
27
+ const { params, methodGet, children } = props;
28
+ const [curdDetailPageData, setCurdDetailPageData] = useState(null);
13
29
  const mtApp = useMtmApp();
14
- const query = useSuspenseQuery(methodGet, params);
15
- return /* @__PURE__ */ jsxs(ScopeAtomsHydrator, { atomValues: [
16
- [curdDetailPageDataAtom, query.data]
17
- ], children: [
30
+ return /* @__PURE__ */ jsxs(CurdDetailContext.Provider, { value: {
31
+ params,
32
+ methodGet,
33
+ curdDetailPageData,
34
+ setCurdDetailPageData
35
+ }, children: [
18
36
  children,
19
37
  mtApp.isDebug && /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(DetailViewDataDlg, {}) })
20
38
  ] });
21
39
  }
40
+ function useDetail() {
41
+ const mtappContext = useContext(CurdDetailContext);
42
+ if (mtappContext === void 0) {
43
+ throw new Error("useMtmApp must be used within a MtAppProvider");
44
+ }
45
+ return __spreadValues({}, mtappContext);
46
+ }
22
47
  const DetailViewDataDlg = () => {
23
- const [curdDetailPageData] = useAtom(curdDetailPageDataAtom);
48
+ const detail = useDetail();
49
+ const query = useSuspenseQuery(detail.methodGet);
24
50
  return /* @__PURE__ */ jsxs(Dialog, { children: [
25
51
  /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "DetailData" }) }),
26
- /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(curdDetailPageData, null, 2) }) })
52
+ /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(query.data, null, 2) }) })
27
53
  ] });
28
54
  };
55
+ function DlgCurdDebugInfo() {
56
+ const listView = useListView();
57
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Dialog, { open: listView.openDebug, onOpenChange: listView.setOpenDebug, children: /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(DialogTitle, { children: "list view info" }) }) }) });
58
+ }
59
+ const DlgCurdDebugInfoTriggerButton = () => {
60
+ const listView = useListView();
61
+ const mtApp = useMtmApp();
62
+ if (!mtApp.isDebug) {
63
+ return null;
64
+ }
65
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MtButton, { onClick: () => {
66
+ listView.setOpenDebug(true);
67
+ }, children: "DlgCurdDebug" }) });
68
+ };
29
69
  export {
30
70
  CurdDetailProvider,
31
71
  DetailViewDataDlg,
32
- curdDetailPageDataAtom
72
+ DlgCurdDebugInfo,
73
+ DlgCurdDebugInfoTriggerButton,
74
+ useDetail
33
75
  };
@@ -0,0 +1,29 @@
1
+ import { Message } from "@bufbuild/protobuf";
2
+ import { Dispatch, PropsWithChildren, SetStateAction } from "react";
3
+ import { MethodUnaryDescriptor } from "../connectquery";
4
+ export declare function ListViewProvider<I extends Message<I>, O extends Message<O>>(props: {
5
+ methodList: MethodUnaryDescriptor<I, any>;
6
+ methodDelete: MethodUnaryDescriptor<any, any>;
7
+ methodCreate?: MethodUnaryDescriptor<any, any>;
8
+ slugPath?: string;
9
+ } & PropsWithChildren): import("react").JSX.Element;
10
+ export declare const useListView: () => {
11
+ methodList?: MethodUnaryDescriptor<any, any> | undefined;
12
+ methodDelete?: MethodUnaryDescriptor<any, any> | undefined;
13
+ methodCreate?: MethodUnaryDescriptor<any, any> | undefined;
14
+ slugPath?: string | undefined;
15
+ activateItem?: any;
16
+ params?: any;
17
+ openRemove?: boolean | undefined;
18
+ setOpenRemove?: Dispatch<SetStateAction<boolean>> | undefined;
19
+ openCreate?: boolean | undefined;
20
+ setOpenCreate?: Dispatch<SetStateAction<boolean>> | undefined;
21
+ setActivateItem?: Dispatch<any> | undefined;
22
+ openEdit?: boolean | undefined;
23
+ setOpenEdit?: Dispatch<SetStateAction<boolean>> | undefined;
24
+ openDebug?: boolean | undefined;
25
+ setOpenDebug?: Dispatch<SetStateAction<boolean>> | undefined;
26
+ setParams?: Dispatch<any> | undefined;
27
+ };
28
+ export declare function CommonListView<I extends Message<I>, O extends Message<O>>(): import("react").JSX.Element | null;
29
+ export declare const ListViewActions: () => import("react").JSX.Element;
@@ -0,0 +1,180 @@
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
+ var __async = (__this, __arguments, generator) => {
19
+ return new Promise((resolve, reject) => {
20
+ var fulfilled = (value) => {
21
+ try {
22
+ step(generator.next(value));
23
+ } catch (e) {
24
+ reject(e);
25
+ }
26
+ };
27
+ var rejected = (value) => {
28
+ try {
29
+ step(generator.throw(value));
30
+ } catch (e) {
31
+ reject(e);
32
+ }
33
+ };
34
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
+ step((generator = generator.apply(__this, __arguments)).next());
36
+ });
37
+ };
38
+ import { jsx, jsxs } from "react/jsx-runtime";
39
+ import { Icons } from "mtxuilib/icons/icons";
40
+ import { cn } from "mtxuilib/lib/utils";
41
+ import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
42
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
43
+ import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
44
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
45
+ import { Suspense, createContext, useContext, useState } from "react";
46
+ import { MtUnaryCallErrorView } from "../components/MtUnaryCallErrorView";
47
+ import { useMutation, useSuspenseInfiniteQuery } from "../connectquery";
48
+ import { DlgCurdDebugInfo, DlgCurdDebugInfoTriggerButton } from "./CurdDetailProvider";
49
+ import CurdCreatePanel, { CurdCreatePanelTriggerButton } from "./create/CurdCreatePanel";
50
+ import CurdEditPanel, { CurdEditPanelTriggerButton } from "./edit/CurdEditPanel";
51
+ import { ListItemView } from "./list-item/ListItem";
52
+ import { ListLayout } from "./list-item/ListLayout";
53
+ const commonListViewContext = createContext(void 0);
54
+ function ListViewProvider(props) {
55
+ const { children, methodList, methodDelete, slugPath, methodCreate } = props;
56
+ const [openRemove, setOpenRemove] = useState(false);
57
+ const [openCreate, setOpenCreate] = useState(false);
58
+ const [activateItem, setActivateItem] = useState(void 0);
59
+ const [openEdit, setOpenEdit] = useState(false);
60
+ const [openDebug, setOpenDebug] = useState(false);
61
+ const [params, setParams] = useState(void 0);
62
+ return /* @__PURE__ */ jsx(commonListViewContext.Provider, { value: {
63
+ methodList,
64
+ slugPath,
65
+ openRemove,
66
+ setOpenRemove,
67
+ methodDelete,
68
+ methodCreate,
69
+ openCreate,
70
+ setOpenCreate,
71
+ activateItem,
72
+ setActivateItem,
73
+ openEdit,
74
+ setOpenEdit,
75
+ openDebug,
76
+ setOpenDebug,
77
+ params,
78
+ setParams
79
+ }, children });
80
+ }
81
+ const useListView = () => {
82
+ const ctx = useContext(commonListViewContext);
83
+ return __spreadValues({}, ctx);
84
+ };
85
+ function CommonListView() {
86
+ const a = useListView();
87
+ const listQuery = useSuspenseInfiniteQuery(a.methodList, {
88
+ page: 1
89
+ }, {
90
+ pageParamKey: "pagination",
91
+ getNextPageParam: (res, b, c) => {
92
+ return {
93
+ page: ((c == null ? void 0 : c.page) || 0) + 1
94
+ };
95
+ }
96
+ });
97
+ if (!(listQuery == null ? void 0 : listQuery.data)) {
98
+ return null;
99
+ }
100
+ return /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
101
+ /* @__PURE__ */ jsx(
102
+ "div",
103
+ {
104
+ className: cn(
105
+ "w-full"
106
+ // 滚动设置
107
+ // " max-h-[700px] overflow-y-auto"
108
+ ),
109
+ children: listQuery.data.pages.map((page, i) => {
110
+ var _a;
111
+ if (page.error_code) {
112
+ return /* @__PURE__ */ jsx(MtUnaryCallErrorView, { unaryError: page }, i);
113
+ } else {
114
+ return /* @__PURE__ */ jsx(ListLayout, { layout: page.listLayout, children: (_a = page == null ? void 0 : page.items) == null ? void 0 : _a.map((item, j) => /* @__PURE__ */ jsx(ListItemView, { item }, `${i}-${j}`)) }, i);
115
+ }
116
+ })
117
+ }
118
+ ),
119
+ /* @__PURE__ */ jsx(Pagination, { children: /* @__PURE__ */ jsxs(PaginationContent, { children: [
120
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationPrevious, { href: "#" }) }),
121
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "1" }) }),
122
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", isActive: true, children: "2" }) }),
123
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationLink, { href: "#", children: "3" }) }),
124
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
125
+ /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
126
+ ] }) }),
127
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1", children: /* @__PURE__ */ jsx(ListViewActions, {}) })
128
+ ] });
129
+ }
130
+ const PanelRemove = () => {
131
+ const listView = useListView();
132
+ const mutation = useMutation(listView.methodDelete);
133
+ return /* @__PURE__ */ jsx(Dialog, { open: listView.openRemove, onOpenChange: listView.setOpenRemove, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
134
+ /* @__PURE__ */ jsx(DialogTitle, { children: "remove item" }),
135
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => __async(void 0, null, function* () {
136
+ var _a;
137
+ yield mutation.mutateAsync({
138
+ id: (_a = listView.activateItem) == null ? void 0 : _a.id
139
+ });
140
+ listView.setOpenRemove(false);
141
+ }), children: "ok" })
142
+ ] }) });
143
+ };
144
+ const PanelCreate = () => {
145
+ const listView = useListView();
146
+ return /* @__PURE__ */ jsx(Dialog, { open: listView.openCreate, onOpenChange: listView.setOpenCreate, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
147
+ /* @__PURE__ */ jsx(DialogTitle, { children: "TODO create item Dlg" }),
148
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => __async(void 0, null, function* () {
149
+ listView.setOpenCreate(false);
150
+ }), children: "ok" })
151
+ ] }) });
152
+ };
153
+ const ListViewActions = () => {
154
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
155
+ /* @__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, {}) }) }),
156
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { className: "w-56", children: [
157
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Edit" }),
158
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
159
+ /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
160
+ /* @__PURE__ */ jsx(PanelRemove, {}),
161
+ /* @__PURE__ */ jsx(PanelCreate, {}),
162
+ /* @__PURE__ */ jsx(DlgCurdDebugInfo, {}),
163
+ /* @__PURE__ */ jsx(CurdCreatePanel, {}),
164
+ /* @__PURE__ */ jsx(CurdEditPanel, {}),
165
+ /* @__PURE__ */ jsxs("div", { className: "bg-yellow-100 p-2", children: [
166
+ /* @__PURE__ */ jsx(DlgCurdDebugInfoTriggerButton, {}),
167
+ /* @__PURE__ */ jsx(CurdEditPanelTriggerButton, {}),
168
+ /* @__PURE__ */ jsx(CurdCreatePanelTriggerButton, {})
169
+ ] })
170
+ ] }) }) }),
171
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {})
172
+ ] })
173
+ ] });
174
+ };
175
+ export {
176
+ CommonListView,
177
+ ListViewActions,
178
+ ListViewProvider,
179
+ useListView
180
+ };
@@ -1,11 +1,9 @@
1
1
  "use client";
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
- import { useMtRouter } from "mtxuilib/hooks/use-router";
4
3
  import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
5
4
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
6
- import { useListView } from "../CommonListViewV2";
5
+ import { useListView } from "../ListViewProvider";
7
6
  function CurdCreatePanel() {
8
- const router = useMtRouter();
9
7
  const listView = useListView();
10
8
  return /* @__PURE__ */ jsx(Dialog, { open: listView.openCreate, onOpenChange: listView.setOpenCreate, children: /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(DialogTitle, { children: " Create " }) }) });
11
9
  }
@@ -2,7 +2,7 @@
2
2
  import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { Dialog, DialogContent, DialogTitle } from "mtxuilib/ui/dialog";
4
4
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
5
- import { useListView } from "../CommonListViewV2";
5
+ import { useListView } from "../ListViewProvider";
6
6
  function CurdEditPanel() {
7
7
  const listView = useListView();
8
8
  return /* @__PURE__ */ jsx(Dialog, { open: listView.openEdit, onOpenChange: listView.setOpenEdit, children: /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(DialogTitle, { children: " Edit " }) }) });
@@ -7,7 +7,7 @@ import { buttonVariants } from "mtxuilib/ui/button";
7
7
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
8
8
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
9
9
  import { DropdownMenuItemLink } from "mtxuilib/ui/ui-mt/DropdownMenuItemLink";
10
- import { useListView } from "../CommonListViewV2";
10
+ import { useListView } from "../ListViewProvider";
11
11
  const CommonListItemView = (props) => {
12
12
  const { item } = props;
13
13
  const handleSelect = () => {
@@ -6,7 +6,7 @@ import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }
6
6
  import { Icons } from "mtxuilib/icons/icons";
7
7
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
8
8
  import { DropdownMenuItemLink } from "mtxuilib/ui/ui-mt/DropdownMenuItemLink";
9
- import { useListView } from "../CommonListViewV2";
9
+ import { useListView } from "../ListViewProvider";
10
10
  const PostCardListItem = (props) => {
11
11
  var _a;
12
12
  const { item } = props;
@@ -38,7 +38,7 @@ const LzHelloLazyLayout = dynamic(() => import("./Lazy").then((x) => x.HelloLazy
38
38
  });
39
39
  const LayoutBase = (props) => {
40
40
  const { layoutName, children } = props;
41
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(TooltipProvider, { delayDuration: 0, children: [
41
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(TooltipProvider, { delayDuration: 0, children: [
42
42
  layoutName == "front" ? /* @__PURE__ */ jsx(FrontLayout, { children }) : layoutName == "dash5" ? /* @__PURE__ */ jsx(LzDash5, { children }) : layoutName == "debug" ? /* @__PURE__ */ jsx(LzDebugLayout, { children }) : (
43
43
  // layoutName == "demo1" ? <LzDemo>{children}</LzDemo> :
44
44
  layoutName == "demo1" ? /* @__PURE__ */ jsx(Demo1Layout, { children }) : layoutName == "default" ? /* @__PURE__ */ jsx(Fragment, { children }) : children
@@ -57,7 +57,7 @@ const LayoutBase = (props) => {
57
57
  /* @__PURE__ */ jsx(TailwindIndicator, {}),
58
58
  /* @__PURE__ */ jsx(AppMetaRender, {}),
59
59
  /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(LayoutSwitchDlg, {}) })
60
- ] }) }) });
60
+ ] }) });
61
61
  };
62
62
  const LayoutSwitchDlg = () => {
63
63
  const mtapp = useMtmApp();
@@ -19,11 +19,10 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
  import { Fragment, jsx } from "react/jsx-runtime";
22
- import { ScopeAtomsHydrator } from "mtxlib/jotai/jotai-helper";
23
22
  import { cookies, headers } from "next/headers";
24
23
  import { IsDebugCookie, LayoutNameCookie } from "../consts";
25
24
  import { ssrGetBackendUrl } from "../mtmFetcher";
26
- import { GomtmProvider, cookiesAtom } from "./GomtmProvider";
25
+ import { GomtmProvider } from "./GomtmProvider";
27
26
  function GomtmAppSS(props) {
28
27
  return __async(this, null, function* () {
29
28
  var _a, _b;
@@ -41,10 +40,8 @@ function GomtmAppSS(props) {
41
40
  backendUrl: backend,
42
41
  isDebug,
43
42
  layoutName,
44
- children: /* @__PURE__ */ jsx(ScopeAtomsHydrator, { atomValues: [
45
- [cookiesAtom, cookiesStr]
46
- // [layoutNameAtom, layoutName],
47
- ], children })
43
+ cookieStr: cookiesStr || "",
44
+ children
48
45
  }
49
46
  );
50
47
  });
@@ -1,57 +1,13 @@
1
1
  import { Dispatch, PropsWithChildren, SetStateAction } from 'react';
2
- import { Transport } from '@connectrpc/connect';
3
- export declare const mtmAppStore: {
4
- get: <Value>(atom: import("jotai").Atom<Value>) => Value;
5
- set: <Value_1, Args extends unknown[], Result>(atom: import("jotai").WritableAtom<Value_1, Args, Result>, ...args: Args) => Result;
6
- sub: (atom: import("jotai").Atom<unknown>, listener: () => void) => () => void;
7
- } & Partial<{
8
- dev_subscribe_store: (l: (action: {
9
- type: "write";
10
- flushed: Set<import("jotai").Atom<unknown>>;
11
- } | {
12
- type: "async-write";
13
- flushed: Set<import("jotai").Atom<unknown>>;
14
- } | {
15
- type: "sub";
16
- flushed: Set<import("jotai").Atom<unknown>>;
17
- } | {
18
- type: "unsub";
19
- } | {
20
- type: "restore";
21
- flushed: Set<import("jotai").Atom<unknown>>;
22
- }) => void, rev: 2) => () => void;
23
- dev_get_mounted_atoms: () => IterableIterator<import("jotai").Atom<unknown>>;
24
- dev_get_atom_state: (a: import("jotai").Atom<unknown>) => ({
25
- d: Map<import("jotai").Atom<unknown>, any & ({
26
- e: unknown;
27
- } | {
28
- v: unknown;
29
- })>;
30
- } & ({
31
- e: unknown;
32
- } | {
33
- v: unknown;
34
- })) | undefined;
35
- dev_get_mounted: (a: import("jotai").Atom<unknown>) => {
36
- l: Set<() => void>;
37
- t: Set<import("jotai").Atom<unknown>>;
38
- u?: (() => void) | undefined;
39
- } | undefined;
40
- dev_restore_atoms: (values: Iterable<readonly [import("jotai").Atom<unknown>, unknown]>) => void;
41
- }>;
42
2
  export type ActionHandler = (props: {
43
3
  action: string;
44
4
  values?: any;
45
5
  }) => void;
46
- export declare const gomtmBaseUrlAtom: import("jotai").PrimitiveAtom<string> & {
47
- init: string;
48
- };
49
- export declare const cookiesAtom: import("jotai").WritableAtom<string | undefined, [value: string], void>;
50
- export declare const transportAtom: import("jotai").Atom<Transport>;
51
6
  interface GomtmAppProps {
52
7
  backendUrl?: string | null;
53
8
  isDebug?: boolean;
54
9
  layoutName?: string;
10
+ cookieStr?: string;
55
11
  }
56
12
  export declare function GomtmProvider(props: {} & GomtmAppProps & PropsWithChildren): import("react").JSX.Element;
57
13
  export declare function useMtmApp(): {
@@ -61,9 +17,11 @@ export declare function useMtmApp(): {
61
17
  setLayoutName: Dispatch<SetStateAction<string>>;
62
18
  openLayoutSwitchDlg?: boolean | undefined;
63
19
  setOpenLayoutSwitchDlg: Dispatch<SetStateAction<boolean>>;
20
+ setCookieStr: Dispatch<SetStateAction<string>>;
64
21
  backendUrl?: string | null | undefined;
65
22
  isDebug?: boolean | undefined;
66
23
  layoutName?: string | undefined;
24
+ cookieStr?: string | undefined;
67
25
  };
68
26
  export declare const useHostname: () => string;
69
27
  export declare const MtConnectProvider: (props: PropsWithChildren) => import("react").JSX.Element;
@@ -16,49 +16,13 @@ var __spreadValues = (a, b) => {
16
16
  return a;
17
17
  };
18
18
  import { jsx } from "react/jsx-runtime";
19
- import { createContext, useContext, useState } from "react";
19
+ import { createContext, useContext, useMemo, useState } from "react";
20
20
  import { createConnectTransport } from "@connectrpc/connect-web";
21
- import { atom, createStore, useAtom } from "jotai";
22
21
  import { useHotkeys } from "react-hotkeys-hook";
23
22
  import { TransportProvider } from "../connectquery";
24
23
  import { anypbTypeReg } from "../messageTypeRegistry";
25
24
  import { gomtmFetcher } from "../mtmFetcher";
26
25
  import { MtReactQueryProvider } from "./ReactQueryProvider";
27
- const mtmAppStore = createStore();
28
- const gomtmBaseUrlAtom = atom("");
29
- const curd3BackendUrlAtom = atom((get) => {
30
- const value1 = get(gomtmBaseUrlAtom);
31
- console.log("curd3BackendUrlAtom", value1);
32
- if (value1) {
33
- return value1;
34
- }
35
- if (typeof window == "undefined") {
36
- console.log("get gomtm backendurl(SSR)", process.env.MTM_BACKEND);
37
- return process.env.MTM_BACKEND || "";
38
- }
39
- return "";
40
- });
41
- const cookiesValueAtom = atom(void 0);
42
- const cookiesAtom = atom((get) => {
43
- const v = get(cookiesValueAtom);
44
- return v;
45
- }, (_, set, value) => {
46
- set(cookiesValueAtom, value);
47
- });
48
- const transportAtom = atom((get) => {
49
- const baseUrl = get(curd3BackendUrlAtom);
50
- const cookiesStr = get(cookiesAtom);
51
- const baseApiUrl = new URL("/api", baseUrl).toString();
52
- return createConnectTransport({
53
- baseUrl: baseApiUrl,
54
- fetch: gomtmFetcher({
55
- cookieStr: cookiesStr
56
- }),
57
- jsonOptions: {
58
- typeRegistry: anypbTypeReg
59
- }
60
- });
61
- });
62
26
  const AppContext = createContext(void 0);
63
27
  function GomtmProvider(props) {
64
28
  const { backendUrl, children } = props;
@@ -66,6 +30,7 @@ function GomtmProvider(props) {
66
30
  const [_backendUrl, setBackendUrl] = useState(backendUrl);
67
31
  const [_layoutName, setLayoutName] = useState("front");
68
32
  const [openLayoutSwitchDlg, setOpenLayoutSwitchDlg] = useState(false);
33
+ const [_cookieStr, setCookieStr] = useState("");
69
34
  useHotkeys("alt+j", () => {
70
35
  setDebug(!_isDebug);
71
36
  }, [_isDebug, setDebug]);
@@ -77,7 +42,9 @@ function GomtmProvider(props) {
77
42
  layoutName: _layoutName,
78
43
  setLayoutName,
79
44
  openLayoutSwitchDlg,
80
- setOpenLayoutSwitchDlg
45
+ setOpenLayoutSwitchDlg,
46
+ cookieStr: _cookieStr,
47
+ setCookieStr
81
48
  }, children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsx(MtReactQueryProvider, { children }) }) });
82
49
  }
83
50
  function useMtmApp() {
@@ -98,16 +65,24 @@ const useHostname = () => {
98
65
  };
99
66
  const MtConnectProvider = (props) => {
100
67
  const { children } = props;
101
- const [transport] = useAtom(transportAtom);
68
+ const mtapp = useMtmApp();
69
+ const transport = useMemo(() => {
70
+ const baseApiUrl = new URL("/api", mtapp.backendUrl || "").toString();
71
+ return createConnectTransport({
72
+ baseUrl: baseApiUrl,
73
+ fetch: gomtmFetcher({
74
+ cookieStr: mtapp.cookieStr
75
+ }),
76
+ jsonOptions: {
77
+ typeRegistry: anypbTypeReg
78
+ }
79
+ });
80
+ }, [mtapp.backendUrl, mtapp.cookieStr]);
102
81
  return /* @__PURE__ */ jsx(TransportProvider, { transport, children });
103
82
  };
104
83
  export {
105
84
  GomtmProvider,
106
85
  MtConnectProvider,
107
- cookiesAtom,
108
- gomtmBaseUrlAtom,
109
- mtmAppStore,
110
- transportAtom,
111
86
  useHostname,
112
87
  useMtmApp
113
88
  };