gomtm 0.0.289 → 0.0.291
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.
- package/dist/esm/components/devtools/GoMtmDebug.d.ts +1 -1
- package/dist/esm/components/devtools/GoMtmDebug.js +3 -8
- package/dist/esm/consts.d.ts +1 -2
- package/dist/esm/consts.js +3 -1
- package/dist/esm/curd/create/CurdCreatePanel.js +7 -5
- package/dist/esm/curd/edit/CurdEditPanel.js +8 -6
- package/dist/esm/curd/list-item/CommonListItemView.js +8 -8
- package/dist/esm/curd/list-item/PostCardListItem.js +18 -15
- package/dist/esm/curd/listview/ListViewProvider.d.ts +2 -68
- package/dist/esm/curd/listview/ListViewProvider.js +35 -117
- package/dist/esm/curd/listview/MtListView.d.ts +2 -2
- package/dist/esm/curd/listview/MtListView.js +18 -9
- package/dist/esm/curd/listview/list-store.d.ts +38 -0
- package/dist/esm/curd/listview/list-store.js +80 -0
- package/dist/esm/gomtmQuery.js +7 -7
- package/dist/esm/ly/LayoutBase.js +10 -9
- package/dist/esm/ly/front-layout/PageSearchCmd.js +5 -6
- package/dist/esm/providers/ConfigStateProvider.d.ts +0 -11
- package/dist/esm/providers/ConfigStateProvider.js +0 -44
- package/dist/esm/providers/GomtmAppSS.js +10 -11
- package/dist/esm/providers/GomtmProvider.d.ts +0 -43
- package/dist/esm/providers/GomtmProvider.js +0 -121
- package/dist/esm/providers/ListViewProvider.d.ts +1 -0
- package/dist/esm/providers/ListViewProvider.js +5 -1
- package/dist/esm/store/App_useTransition.d.ts +2 -0
- package/dist/esm/store/App_useTransition.js +59 -0
- package/dist/esm/store/config-store.d.ts +0 -16
- package/dist/esm/store/config-store.js +0 -44
- package/dist/esm/store/list-store.d.ts +11 -1
- package/dist/esm/store/list-store.js +64 -11
- package/dist/esm/store/mtapp-store.d.ts +30 -0
- package/dist/esm/store/mtapp-store.js +118 -0
- package/dist/tsconfig.type.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface ListViewStateProps {
|
|
3
|
+
backendUrl?: string;
|
|
4
|
+
svc: string;
|
|
5
|
+
methodList: string;
|
|
6
|
+
methodGet: string;
|
|
7
|
+
methodDelete: string;
|
|
8
|
+
methodCreate?: string;
|
|
9
|
+
paramsGet?: any;
|
|
10
|
+
paramsList?: any;
|
|
11
|
+
slugPath?: string;
|
|
12
|
+
activateItem?: any;
|
|
13
|
+
detailData?: any;
|
|
14
|
+
layout?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ListViewState extends ListViewStateProps {
|
|
17
|
+
openRemove: boolean;
|
|
18
|
+
setOpenRemove: (openRemove: boolean) => void;
|
|
19
|
+
openCreate: boolean;
|
|
20
|
+
setOpenCreate: (openCreate: boolean) => void;
|
|
21
|
+
openEdit: boolean;
|
|
22
|
+
setOpenEdit: (openEdit: boolean) => void;
|
|
23
|
+
setLayout: (layout: string) => void;
|
|
24
|
+
setActivateItem: (activateItem: any) => void;
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
success?: boolean;
|
|
27
|
+
error?: boolean;
|
|
28
|
+
data?: any;
|
|
29
|
+
errorData?: any;
|
|
30
|
+
demoListData?: any;
|
|
31
|
+
items?: any[];
|
|
32
|
+
value1?: any;
|
|
33
|
+
}
|
|
34
|
+
export declare const listViewContext: import("react").Context<import("zustand").StoreApi<ListViewState> | null>;
|
|
35
|
+
type BearProviderProps = React.PropsWithChildren<ListViewStateProps>;
|
|
36
|
+
export declare const ListViewStoreProvider: (props: BearProviderProps) => import("react").JSX.Element;
|
|
37
|
+
export declare function useListview<T>(selector: (state: ListViewState) => T): T;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
import { jsx } from "react/jsx-runtime";
|
|
34
|
+
import { setCookie } from "mtxlib/clientlib";
|
|
35
|
+
import { createContext, useContext, useRef } from "react";
|
|
36
|
+
import { useStore } from "zustand";
|
|
37
|
+
import { createStore } from "zustand/vanilla";
|
|
38
|
+
import { CONST_cookieListViewLayout } from "../../consts";
|
|
39
|
+
const createListviewStore = (initProps) => {
|
|
40
|
+
const DEFAULT_PROPS = {
|
|
41
|
+
svc: initProps.svc || "",
|
|
42
|
+
methodList: initProps.methodList || "",
|
|
43
|
+
methodGet: "",
|
|
44
|
+
methodDelete: "",
|
|
45
|
+
methodCreate: ""
|
|
46
|
+
};
|
|
47
|
+
return createStore()((set) => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_PROPS), initProps), {
|
|
48
|
+
openRemove: false,
|
|
49
|
+
setOpenRemove: (openRemove) => set({ openRemove }),
|
|
50
|
+
openCreate: false,
|
|
51
|
+
setOpenCreate: (openCreate) => set({ openCreate }),
|
|
52
|
+
openEdit: false,
|
|
53
|
+
setOpenEdit: (openEdit) => set({ openEdit }),
|
|
54
|
+
setActivateItem: (activateItem) => set({ activateItem }),
|
|
55
|
+
setLayout: (layout) => {
|
|
56
|
+
setCookie(CONST_cookieListViewLayout, layout);
|
|
57
|
+
return set((state) => ({ layout }));
|
|
58
|
+
}
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
const listViewContext = createContext(null);
|
|
62
|
+
const ListViewStoreProvider = (props) => {
|
|
63
|
+
const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
|
|
64
|
+
const storeRef = useRef();
|
|
65
|
+
if (!storeRef.current) {
|
|
66
|
+
storeRef.current = createListviewStore(props);
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ jsx(listViewContext.Provider, { value: storeRef.current, children });
|
|
69
|
+
};
|
|
70
|
+
function useListview(selector) {
|
|
71
|
+
const store = useContext(listViewContext);
|
|
72
|
+
if (!store)
|
|
73
|
+
throw new Error("useListview Missing ListViewProvider in the tree");
|
|
74
|
+
return useStore(store, selector);
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
ListViewStoreProvider,
|
|
78
|
+
listViewContext,
|
|
79
|
+
useListview
|
|
80
|
+
};
|
package/dist/esm/gomtmQuery.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useMutation, useQuery, useSuspenseInfiniteQuery, useSuspenseQuery } from "@tanstack/react-query";
|
|
3
3
|
import { MTM_API_PREFIX } from "./consts";
|
|
4
4
|
import { createInfiniteQueryKey, createQueryKey, goMtmQueryFn } from "./mtmFetcher";
|
|
5
|
-
import {
|
|
5
|
+
import { useGomtm } from "./store/mtapp-store";
|
|
6
6
|
const useGomtmQuery = (svc, method, input) => {
|
|
7
7
|
const query = useQuery({
|
|
8
8
|
queryKey: createQueryKey(svc, method, input),
|
|
@@ -11,7 +11,7 @@ const useGomtmQuery = (svc, method, input) => {
|
|
|
11
11
|
return query;
|
|
12
12
|
};
|
|
13
13
|
const useGomtmSuspenseQuery = (svc, method, input) => {
|
|
14
|
-
const
|
|
14
|
+
const backendUrl = useGomtm((x) => x.configState.backendUrl);
|
|
15
15
|
const query = useSuspenseQuery({
|
|
16
16
|
queryKey: createQueryKey(svc, method, input),
|
|
17
17
|
queryFn: (k) => goMtmQueryFn({
|
|
@@ -19,14 +19,14 @@ const useGomtmSuspenseQuery = (svc, method, input) => {
|
|
|
19
19
|
method,
|
|
20
20
|
input,
|
|
21
21
|
options: {
|
|
22
|
-
url: new URL(MTM_API_PREFIX,
|
|
22
|
+
url: new URL(MTM_API_PREFIX, backendUrl).toString()
|
|
23
23
|
}
|
|
24
24
|
})
|
|
25
25
|
});
|
|
26
26
|
return query;
|
|
27
27
|
};
|
|
28
28
|
const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
|
|
29
|
-
const
|
|
29
|
+
const backendUrl = useGomtm((x) => x.configState.backendUrl);
|
|
30
30
|
const query = useSuspenseInfiniteQuery({
|
|
31
31
|
queryKey: createInfiniteQueryKey(svc, method, input),
|
|
32
32
|
queryFn: (k) => goMtmQueryFn({
|
|
@@ -34,7 +34,7 @@ const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
|
|
|
34
34
|
method,
|
|
35
35
|
input,
|
|
36
36
|
options: {
|
|
37
|
-
url: new URL(MTM_API_PREFIX,
|
|
37
|
+
url: new URL(MTM_API_PREFIX, backendUrl).toString()
|
|
38
38
|
}
|
|
39
39
|
}),
|
|
40
40
|
initialPageParam: input,
|
|
@@ -45,14 +45,14 @@ const useGomtmSuspenseInfiniteQuery = (svc, method, input) => {
|
|
|
45
45
|
return query;
|
|
46
46
|
};
|
|
47
47
|
const useGomtmMutation = (svc, method) => {
|
|
48
|
-
const
|
|
48
|
+
const backendUrl = useGomtm((x) => x.configState.backendUrl);
|
|
49
49
|
return useMutation({
|
|
50
50
|
mutationFn: (input) => goMtmQueryFn({
|
|
51
51
|
svc,
|
|
52
52
|
method,
|
|
53
53
|
input,
|
|
54
54
|
options: {
|
|
55
|
-
url: new URL(MTM_API_PREFIX,
|
|
55
|
+
url: new URL(MTM_API_PREFIX, backendUrl).toString()
|
|
56
56
|
}
|
|
57
57
|
})
|
|
58
58
|
});
|
|
@@ -11,7 +11,7 @@ import { Suspense, lazy, useMemo, useState } from "react";
|
|
|
11
11
|
import { useHotkeys } from "react-hotkeys-hook";
|
|
12
12
|
import { Toaster } from "sonner";
|
|
13
13
|
import { HOTKEY_Switchlayout } from "../consts";
|
|
14
|
-
import {
|
|
14
|
+
import { useGomtm } from "../store/mtapp-store";
|
|
15
15
|
const ALL_Layouts = [
|
|
16
16
|
"demo1",
|
|
17
17
|
"dash5",
|
|
@@ -25,9 +25,9 @@ const LzDebugLayout = lazy(() => import("./debug-layout"));
|
|
|
25
25
|
const LzFrontLayout = lazy(() => import("./front-layout"));
|
|
26
26
|
const LayoutBase = (props) => {
|
|
27
27
|
const { children } = props;
|
|
28
|
-
const
|
|
28
|
+
const layout = useGomtm((x) => x.configState.layout);
|
|
29
29
|
const LayoutComponent = useMemo(() => {
|
|
30
|
-
switch (
|
|
30
|
+
switch (layout) {
|
|
31
31
|
case "dash5":
|
|
32
32
|
return LzDash5;
|
|
33
33
|
case "debug":
|
|
@@ -37,7 +37,7 @@ const LayoutBase = (props) => {
|
|
|
37
37
|
default:
|
|
38
38
|
return LzFrontLayout;
|
|
39
39
|
}
|
|
40
|
-
}, [
|
|
40
|
+
}, [layout]);
|
|
41
41
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(TooltipProvider, { delayDuration: 0, children: [
|
|
42
42
|
/* @__PURE__ */ jsx(LayoutComponent, { children }),
|
|
43
43
|
/* @__PURE__ */ jsx(
|
|
@@ -57,7 +57,8 @@ const LayoutBase = (props) => {
|
|
|
57
57
|
] }) });
|
|
58
58
|
};
|
|
59
59
|
const LayoutSwitchDlg = () => {
|
|
60
|
-
const
|
|
60
|
+
const layout = useGomtm((x) => x.configState.layout);
|
|
61
|
+
const setLayout = useGomtm((x) => x.setLayout);
|
|
61
62
|
const [open, setOpen] = useState(false);
|
|
62
63
|
useHotkeys(HOTKEY_Switchlayout, () => {
|
|
63
64
|
setOpen((pre) => !pre);
|
|
@@ -65,13 +66,13 @@ const LayoutSwitchDlg = () => {
|
|
|
65
66
|
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
66
67
|
/* @__PURE__ */ jsxs(DialogTitle, { children: [
|
|
67
68
|
"LayoutSwitch,",
|
|
68
|
-
|
|
69
|
+
layout
|
|
69
70
|
] }),
|
|
70
|
-
/* @__PURE__ */ jsx("div", { className: "flex gap-2 bg-red-100 p-2", children: ALL_Layouts.map((
|
|
71
|
+
/* @__PURE__ */ jsx("div", { className: "flex gap-2 bg-red-100 p-2", children: ALL_Layouts.map((layout2) => {
|
|
71
72
|
return /* @__PURE__ */ jsx(MtButton, { onClick: () => {
|
|
72
|
-
|
|
73
|
+
setLayout(layout2);
|
|
73
74
|
setOpen(false);
|
|
74
|
-
}, children:
|
|
75
|
+
}, children: layout2 }, layout2);
|
|
75
76
|
}) })
|
|
76
77
|
] }) });
|
|
77
78
|
};
|
|
@@ -26,15 +26,14 @@ 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 {
|
|
29
|
+
import { useGomtm } from "../../store/mtapp-store";
|
|
30
30
|
const PageSearchCmd = () => {
|
|
31
|
-
var _a;
|
|
32
31
|
const [open, setOpen] = useState(false);
|
|
33
32
|
useHotkeys("alt+s", () => {
|
|
34
33
|
setOpen((open2) => !open2);
|
|
35
34
|
}, []);
|
|
36
|
-
const
|
|
37
|
-
const
|
|
35
|
+
const globalSearchParams = useGomtm((x) => x.globalSearchParams);
|
|
36
|
+
const setSearchParams = useGomtm((x) => x.setGlobalSearchParams);
|
|
38
37
|
const form = useForm();
|
|
39
38
|
return /* @__PURE__ */ jsxs(MtForm, __spreadProps(__spreadValues({}, form), { children: [
|
|
40
39
|
/* @__PURE__ */ jsx("form", { onSubmit: form.handleSubmit(() => {
|
|
@@ -46,9 +45,9 @@ const PageSearchCmd = () => {
|
|
|
46
45
|
type: "search",
|
|
47
46
|
placeholder: "Search...",
|
|
48
47
|
className: "bg-background w-full rounded-lg pl-8 md:w-[200px] lg:w-[336px]",
|
|
49
|
-
defaultValue:
|
|
48
|
+
defaultValue: globalSearchParams == null ? void 0 : globalSearchParams.q,
|
|
50
49
|
onChange: (e) => {
|
|
51
|
-
|
|
50
|
+
setSearchParams({
|
|
52
51
|
q: e.target.value
|
|
53
52
|
});
|
|
54
53
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import { type StoreApi } from 'zustand';
|
|
3
|
-
import { ConfigStore } from "../store/config-store";
|
|
4
|
-
export declare const CounterStoreContext: import("react").Context<StoreApi<ConfigStore> | null>;
|
|
5
|
-
export interface ConfigStoreProviderProps {
|
|
6
|
-
debug?: boolean;
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
export declare const ConfigStoreProvider: ({ children, }: ConfigStoreProviderProps) => import("react").JSX.Element;
|
|
10
|
-
export declare const SetupDebugHotKey: () => null;
|
|
11
|
-
export declare const useConfigStore: <T>(selector: (store: ConfigStore) => T) => T;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useRef } from "react";
|
|
4
|
-
import { useHotkeys } from "react-hotkeys-hook";
|
|
5
|
-
import { useStore } from "zustand";
|
|
6
|
-
import { HOTKEY_Debug } from "../consts";
|
|
7
|
-
import { createConfigStore, initConfigStore } from "../store/config-store";
|
|
8
|
-
const CounterStoreContext = createContext(
|
|
9
|
-
null
|
|
10
|
-
);
|
|
11
|
-
const ConfigStoreProvider = ({
|
|
12
|
-
children
|
|
13
|
-
}) => {
|
|
14
|
-
const storeRef = useRef();
|
|
15
|
-
if (!storeRef.current) {
|
|
16
|
-
storeRef.current = createConfigStore(initConfigStore());
|
|
17
|
-
}
|
|
18
|
-
return /* @__PURE__ */ jsxs(CounterStoreContext.Provider, { value: storeRef.current, children: [
|
|
19
|
-
children,
|
|
20
|
-
/* @__PURE__ */ jsx(SetupDebugHotKey, {})
|
|
21
|
-
] });
|
|
22
|
-
};
|
|
23
|
-
const SetupDebugHotKey = () => {
|
|
24
|
-
const debug = useConfigStore((x) => x.debug);
|
|
25
|
-
const setDebug = useConfigStore((x) => x.setDebug);
|
|
26
|
-
useHotkeys(HOTKEY_Debug, () => {
|
|
27
|
-
console.log("set debug", debug);
|
|
28
|
-
setDebug(!debug);
|
|
29
|
-
}, [debug, setDebug]);
|
|
30
|
-
return null;
|
|
31
|
-
};
|
|
32
|
-
const useConfigStore = (selector) => {
|
|
33
|
-
const counterStoreContext = useContext(CounterStoreContext);
|
|
34
|
-
if (!counterStoreContext) {
|
|
35
|
-
throw new Error(`useConfigStore must be use within ConfigStoreProvider`);
|
|
36
|
-
}
|
|
37
|
-
return useStore(counterStoreContext, selector);
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
ConfigStoreProvider,
|
|
41
|
-
CounterStoreContext,
|
|
42
|
-
SetupDebugHotKey,
|
|
43
|
-
useConfigStore
|
|
44
|
-
};
|
|
@@ -20,12 +20,12 @@ 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 {
|
|
23
|
+
import { getGomtmConfig } from "../consts";
|
|
24
24
|
import { ssrGetBackendUrl } from "../mtmFetcher";
|
|
25
|
-
import {
|
|
25
|
+
import { GoMtmAppProvider } from "../store/mtapp-store";
|
|
26
26
|
function GomtmAppSS(props) {
|
|
27
27
|
return __async(this, null, function* () {
|
|
28
|
-
var _a, _b
|
|
28
|
+
var _a, _b;
|
|
29
29
|
const { children } = props;
|
|
30
30
|
const gomtmAppConfig = getGomtmConfig();
|
|
31
31
|
let backend = ssrGetBackendUrl();
|
|
@@ -37,18 +37,17 @@ function GomtmAppSS(props) {
|
|
|
37
37
|
return /* @__PURE__ */ jsx(Fragment, { children: "missing backend" });
|
|
38
38
|
}
|
|
39
39
|
const cookiesStr = headers().get("Cookie");
|
|
40
|
-
const
|
|
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) || "{}";
|
|
40
|
+
const configStateJson = ((_b = cookies().get(gomtmAppConfig.CookieConfigState)) == null ? void 0 : _b.value) || "{}";
|
|
43
41
|
const configState = JSON.parse(configStateJson);
|
|
42
|
+
if (!configState.backendUrl) {
|
|
43
|
+
configState.backendUrl = backend;
|
|
44
|
+
}
|
|
44
45
|
return /* @__PURE__ */ jsx(
|
|
45
|
-
|
|
46
|
+
GoMtmAppProvider,
|
|
46
47
|
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
layoutName,
|
|
48
|
+
configState,
|
|
49
|
+
params: {},
|
|
50
50
|
cookieStr: cookiesStr || "",
|
|
51
|
-
config: gomtmAppConfig,
|
|
52
51
|
children
|
|
53
52
|
}
|
|
54
53
|
);
|
|
@@ -1,47 +1,4 @@
|
|
|
1
|
-
import { Dispatch, PropsWithChildren, SetStateAction } from 'react';
|
|
2
|
-
import { getGomtmConfig } from '../consts';
|
|
3
|
-
import { ConfigState } from '../store/config-store';
|
|
4
1
|
export type ActionHandler = (props: {
|
|
5
2
|
action: string;
|
|
6
3
|
values?: any;
|
|
7
4
|
}) => void;
|
|
8
|
-
interface GomtmAppProps {
|
|
9
|
-
config: ReturnType<typeof getGomtmConfig>;
|
|
10
|
-
backendUrl?: string | null;
|
|
11
|
-
layoutName?: string;
|
|
12
|
-
listviewLayout?: string;
|
|
13
|
-
cookieStr?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function GomtmProvider(props: {} & GomtmAppProps & ConfigState & PropsWithChildren): import("react").JSX.Element;
|
|
16
|
-
export declare function useMtmApp(): {
|
|
17
|
-
hostname?: string | null | undefined;
|
|
18
|
-
setBackendUrl: Dispatch<SetStateAction<string | null | undefined>>;
|
|
19
|
-
setLayout: (arg0: string) => void;
|
|
20
|
-
setListViewLayout: (arg0: string) => void;
|
|
21
|
-
setCookieStr: Dispatch<SetStateAction<string>>;
|
|
22
|
-
globalSearchParams?: any;
|
|
23
|
-
setGlobalSearchParams: Dispatch<any>;
|
|
24
|
-
setConfig: Dispatch<SetStateAction<{
|
|
25
|
-
cookieBackendUrl: string;
|
|
26
|
-
cookieListViewLayout: string;
|
|
27
|
-
CookieLayout: string;
|
|
28
|
-
CookieConfigState: string;
|
|
29
|
-
}>>;
|
|
30
|
-
config: {
|
|
31
|
-
cookieBackendUrl: string;
|
|
32
|
-
cookieListViewLayout: string;
|
|
33
|
-
CookieLayout: string;
|
|
34
|
-
CookieConfigState: string;
|
|
35
|
-
};
|
|
36
|
-
backendUrl?: string | null | undefined;
|
|
37
|
-
layoutName?: string | undefined;
|
|
38
|
-
listviewLayout?: string | undefined;
|
|
39
|
-
cookieStr?: string | undefined;
|
|
40
|
-
};
|
|
41
|
-
export declare const useHostname: () => string;
|
|
42
|
-
export declare const MtConnectProvider: (props: PropsWithChildren) => import("react").JSX.Element;
|
|
43
|
-
export declare const useGlobalsearchParams: () => {
|
|
44
|
-
searchParams: any;
|
|
45
|
-
setSearchParams: Dispatch<any>;
|
|
46
|
-
};
|
|
47
|
-
export {};
|
|
@@ -1,122 +1 @@
|
|
|
1
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
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
import { createContext, useCallback, useContext, useMemo, useState } from "react";
|
|
20
|
-
import { createConnectTransport } from "@connectrpc/connect-web";
|
|
21
|
-
import { debounce } from "lodash";
|
|
22
|
-
import { setCookie } from "mtxlib/clientlib";
|
|
23
|
-
import { useSearchParams } from "next/navigation";
|
|
24
|
-
import { GoMtmDebug } from "../components/devtools/GoMtmDebug";
|
|
25
|
-
import { TransportProvider } from "../connectquery";
|
|
26
|
-
import { getGomtmConfig } from "../consts";
|
|
27
|
-
import { anypbTypeReg } from "../messageTypeRegistry";
|
|
28
|
-
import { gomtmFetcher } from "../mtmFetcher";
|
|
29
|
-
import { ConfigStoreProvider } from "./ConfigStateProvider";
|
|
30
|
-
import { MtReactQueryProvider } from "./ReactQueryProvider";
|
|
31
|
-
const AppContext = createContext(void 0);
|
|
32
|
-
function GomtmProvider(props) {
|
|
33
|
-
const { backendUrl, layoutName, debug, children, listviewLayout, config } = props;
|
|
34
|
-
const [_config, setConfig] = useState(config);
|
|
35
|
-
const [_backendUrl, setBackendUrl] = useState(backendUrl);
|
|
36
|
-
const [_layoutName, setLayoutName] = useState(layoutName);
|
|
37
|
-
const [_listviewLayout, _setListViewLayout] = useState(listviewLayout);
|
|
38
|
-
const [_cookieStr, setCookieStr] = useState("");
|
|
39
|
-
const [_globalSearchParams, _setGlobalSearchParams] = useState({});
|
|
40
|
-
const searchParams = useSearchParams();
|
|
41
|
-
const setGlobalSearchParams = useCallback(debounce((values) => {
|
|
42
|
-
_setGlobalSearchParams(values);
|
|
43
|
-
}, 200), [_setGlobalSearchParams]);
|
|
44
|
-
const globalSearchParams = useMemo(() => {
|
|
45
|
-
const q = searchParams.get("q");
|
|
46
|
-
return __spreadValues({ q }, _globalSearchParams);
|
|
47
|
-
}, [searchParams, _globalSearchParams]);
|
|
48
|
-
const setLayout = useCallback((name) => {
|
|
49
|
-
setLayoutName(name);
|
|
50
|
-
setCookie(config == null ? void 0 : config.CookieLayout, name);
|
|
51
|
-
}, [config == null ? void 0 : config.CookieLayout]);
|
|
52
|
-
const setListViewLayout = useCallback((name) => {
|
|
53
|
-
setLayoutName(name);
|
|
54
|
-
setCookie(getGomtmConfig().cookieListViewLayout, name);
|
|
55
|
-
}, []);
|
|
56
|
-
return /* @__PURE__ */ jsx(AppContext.Provider, { value: {
|
|
57
|
-
config,
|
|
58
|
-
setConfig,
|
|
59
|
-
backendUrl,
|
|
60
|
-
setBackendUrl,
|
|
61
|
-
layoutName: _layoutName,
|
|
62
|
-
setLayout,
|
|
63
|
-
setListViewLayout,
|
|
64
|
-
listviewLayout,
|
|
65
|
-
cookieStr: _cookieStr,
|
|
66
|
-
setCookieStr,
|
|
67
|
-
globalSearchParams,
|
|
68
|
-
setGlobalSearchParams
|
|
69
|
-
}, children: /* @__PURE__ */ jsx(ConfigStoreProvider, { debug, children: /* @__PURE__ */ jsx(MtConnectProvider, { children: /* @__PURE__ */ jsxs(MtReactQueryProvider, { children: [
|
|
70
|
-
children,
|
|
71
|
-
/* @__PURE__ */ jsx(GoMtmDebug, {})
|
|
72
|
-
] }) }) }) });
|
|
73
|
-
}
|
|
74
|
-
function useMtmApp() {
|
|
75
|
-
const mtappContext = useContext(AppContext);
|
|
76
|
-
if (mtappContext === void 0) {
|
|
77
|
-
throw new Error("useMtmApp must be used within a GomtmProvider");
|
|
78
|
-
}
|
|
79
|
-
return __spreadValues({}, mtappContext);
|
|
80
|
-
}
|
|
81
|
-
const useHostname = () => {
|
|
82
|
-
const { hostname } = useMtmApp();
|
|
83
|
-
if (hostname)
|
|
84
|
-
return hostname;
|
|
85
|
-
if (typeof window != "undefined") {
|
|
86
|
-
return window.location.host;
|
|
87
|
-
}
|
|
88
|
-
return "";
|
|
89
|
-
};
|
|
90
|
-
const MtConnectProvider = (props) => {
|
|
91
|
-
const { children } = props;
|
|
92
|
-
const mtapp = useMtmApp();
|
|
93
|
-
const transport = useMemo(() => {
|
|
94
|
-
const baseApiUrl = new URL("/api", mtapp.backendUrl || "").toString();
|
|
95
|
-
return createConnectTransport({
|
|
96
|
-
baseUrl: baseApiUrl,
|
|
97
|
-
fetch: gomtmFetcher({
|
|
98
|
-
cookieStr: mtapp.cookieStr
|
|
99
|
-
}),
|
|
100
|
-
jsonOptions: {
|
|
101
|
-
typeRegistry: anypbTypeReg
|
|
102
|
-
},
|
|
103
|
-
useHttpGet: true,
|
|
104
|
-
useBinaryFormat: false
|
|
105
|
-
});
|
|
106
|
-
}, [mtapp.backendUrl, mtapp.cookieStr]);
|
|
107
|
-
return /* @__PURE__ */ jsx(TransportProvider, { transport, children });
|
|
108
|
-
};
|
|
109
|
-
const useGlobalsearchParams = () => {
|
|
110
|
-
const mtapp = useMtmApp();
|
|
111
|
-
return {
|
|
112
|
-
searchParams: mtapp.globalSearchParams,
|
|
113
|
-
setSearchParams: mtapp.setGlobalSearchParams
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
export {
|
|
117
|
-
GomtmProvider,
|
|
118
|
-
MtConnectProvider,
|
|
119
|
-
useGlobalsearchParams,
|
|
120
|
-
useHostname,
|
|
121
|
-
useMtmApp
|
|
122
|
-
};
|
|
@@ -5,6 +5,7 @@ export declare const ListViewStoreContext: import("react").Context<StoreApi<List
|
|
|
5
5
|
export interface ListViewStoreProviderProps {
|
|
6
6
|
svc: string;
|
|
7
7
|
methodList: string;
|
|
8
|
+
params?: any;
|
|
8
9
|
children: ReactNode;
|
|
9
10
|
}
|
|
10
11
|
export declare const ListViewStoreProvider: (props: ListViewStoreProviderProps & ListViewStoreProviderProps) => import("react").JSX.Element;
|
|
@@ -15,7 +15,7 @@ var __objRest = (source, exclude) => {
|
|
|
15
15
|
return target;
|
|
16
16
|
};
|
|
17
17
|
import { jsx } from "react/jsx-runtime";
|
|
18
|
-
import { createContext, useContext, useRef } from "react";
|
|
18
|
+
import { createContext, use, useContext, useRef } from "react";
|
|
19
19
|
import { useStore } from "zustand";
|
|
20
20
|
import { createListviewStore, initListViewStore } from "../store/list-store";
|
|
21
21
|
const ListViewStoreContext = createContext(
|
|
@@ -26,7 +26,9 @@ const ListViewStoreProvider = (props) => {
|
|
|
26
26
|
const storeRef = useRef();
|
|
27
27
|
if (!storeRef.current) {
|
|
28
28
|
storeRef.current = createListviewStore(initListViewStore(etc));
|
|
29
|
+
use(storeRef.current.getState().demoFetchPost2("1"));
|
|
29
30
|
}
|
|
31
|
+
console.log("22222222222222222State", storeRef.current.getState());
|
|
30
32
|
return /* @__PURE__ */ jsx(ListViewStoreContext.Provider, { value: storeRef.current, children });
|
|
31
33
|
};
|
|
32
34
|
const useListviewStore = (selector) => {
|
|
@@ -34,6 +36,8 @@ const useListviewStore = (selector) => {
|
|
|
34
36
|
if (!listviewStoreContext) {
|
|
35
37
|
throw new Error(`useListviewStore must be use within ListViewStoreProvider`);
|
|
36
38
|
}
|
|
39
|
+
const state = listviewStoreContext.getState();
|
|
40
|
+
console.log("sate1111111", state);
|
|
37
41
|
return useStore(listviewStoreContext, selector);
|
|
38
42
|
};
|
|
39
43
|
export {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Suspense, use, useEffect, useReducer, useTransition } from "react";
|
|
3
|
+
import { createStore } from "zustand";
|
|
4
|
+
const postStore = createStore((set) => ({
|
|
5
|
+
post: fetch(`https://jsonplaceholder.typicode.com/posts/1`).then(
|
|
6
|
+
(res) => res.json()
|
|
7
|
+
),
|
|
8
|
+
fetchPost: (id) => {
|
|
9
|
+
set({
|
|
10
|
+
post: fetch(
|
|
11
|
+
`https://jsonplaceholder.typicode.com/posts/${id}`
|
|
12
|
+
).then((res) => res.json())
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
const usePostStore = (selector) => {
|
|
17
|
+
const getValue = () => selector(postStore.getState());
|
|
18
|
+
const [value, dispatch] = useReducer(getValue, void 0, getValue);
|
|
19
|
+
useEffect(() => postStore.subscribe(dispatch), [selector]);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
const Post = () => {
|
|
23
|
+
const post = use(usePostStore((state) => state.post));
|
|
24
|
+
return /* @__PURE__ */ jsxs("ul", { children: [
|
|
25
|
+
/* @__PURE__ */ jsxs("li", { children: [
|
|
26
|
+
"ID: ",
|
|
27
|
+
post.id
|
|
28
|
+
] }),
|
|
29
|
+
/* @__PURE__ */ jsxs("li", { children: [
|
|
30
|
+
"Title: ",
|
|
31
|
+
post.title
|
|
32
|
+
] }),
|
|
33
|
+
/* @__PURE__ */ jsxs("li", { children: [
|
|
34
|
+
"Body: ",
|
|
35
|
+
post.body
|
|
36
|
+
] })
|
|
37
|
+
] });
|
|
38
|
+
};
|
|
39
|
+
const DemoPostApp = () => {
|
|
40
|
+
const [isPending, startTransition] = useTransition();
|
|
41
|
+
const fetchPostOrig = usePostStore((state) => state.fetchPost);
|
|
42
|
+
const fetchPost = (id) => {
|
|
43
|
+
startTransition(() => {
|
|
44
|
+
fetchPostOrig(id);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
48
|
+
/* @__PURE__ */ jsx("button", { onClick: () => fetchPost(1), children: "Fetch post 1" }),
|
|
49
|
+
/* @__PURE__ */ jsx("button", { onClick: () => fetchPost(2), children: "Fetch post 2" }),
|
|
50
|
+
/* @__PURE__ */ jsx("button", { onClick: () => fetchPost(3), children: "Fetch post 3" }),
|
|
51
|
+
/* @__PURE__ */ jsx("button", { onClick: () => fetchPost(4), children: "Fetch post 4" }),
|
|
52
|
+
isPending && /* @__PURE__ */ jsx("div", { children: "Pending..." }),
|
|
53
|
+
/* @__PURE__ */ jsx("hr", {}),
|
|
54
|
+
/* @__PURE__ */ jsx(Suspense, { fallback: "Loading...", children: /* @__PURE__ */ jsx(Post, {}) })
|
|
55
|
+
] });
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
DemoPostApp
|
|
59
|
+
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface ConfigState {
|
|
2
|
-
debug?: boolean;
|
|
3
|
-
theme?: string;
|
|
4
|
-
layout?: string;
|
|
5
|
-
listviewLayout?: string;
|
|
6
|
-
}
|
|
7
|
-
export type ConfigActions = {
|
|
8
|
-
setLayout: () => void;
|
|
9
|
-
setDebug: (debug: boolean) => void;
|
|
10
|
-
setTheme: (theme: string) => void;
|
|
11
|
-
setListViewLayout: (listviewLayout: string) => void;
|
|
12
|
-
};
|
|
13
|
-
export declare const initConfigStore: () => ConfigState;
|
|
14
|
-
export declare const defaultInitState: ConfigState;
|
|
15
|
-
export declare const createConfigStore: (initState?: ConfigState) => import("zustand").StoreApi<ConfigStore>;
|
|
16
|
-
export type ConfigStore = ConfigState & ConfigActions;
|