gomtm 0.0.351 → 0.0.352

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.
@@ -37,10 +37,8 @@ import { createStore, useStore } from "zustand";
37
37
  import { useSuspenseQuery } from "../connectquery";
38
38
  import { curdViewGet } from "../gomtmpb/mtm/sppb/mtm-MtmService_connectquery";
39
39
  import { CurdView } from "../gomtmpb/mtm/sppb/mtm_pb";
40
- import CurdEditPanel from "./edit/CurdEditPanel";
41
40
  import { CommonListView } from "./listview/CommonListView";
42
41
  import { ListViewStoreProvider } from "./listview/list-store";
43
- import { PanelRemove } from "./remove/RemovePanel";
44
42
  const createListviewStore = (initProps) => {
45
43
  const DEFAULT_PROPS = {
46
44
  backendUrl: "",
@@ -84,7 +82,7 @@ const CurdViewView = (props) => {
84
82
  return /* @__PURE__ */ jsx("div", { children: "missing curd data222" });
85
83
  }
86
84
  const curdViewData = query.data.item.value;
87
- return /* @__PURE__ */ jsx(CurdViewProvider, { curdView: curdViewData, children: /* @__PURE__ */ jsxs(
85
+ return /* @__PURE__ */ jsx(CurdViewProvider, { curdView: curdViewData, children: /* @__PURE__ */ jsx(
88
86
  ListViewStoreProvider,
89
87
  {
90
88
  slugPath: "/post",
@@ -96,13 +94,7 @@ const CurdViewView = (props) => {
96
94
  methodDelete: curdViewData.methodDelete,
97
95
  viewUpdate: curdViewData.routeEdit,
98
96
  viewCreate: curdViewData.routeCreate,
99
- children: [
100
- /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading CommonListView" }), children: /* @__PURE__ */ jsx(CommonListView, {}) }),
101
- /* @__PURE__ */ jsxs(Suspense, { children: [
102
- /* @__PURE__ */ jsx(CurdEditPanel, { fullScreen: true }),
103
- /* @__PURE__ */ jsx(PanelRemove, {})
104
- ] })
105
- ]
97
+ children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading CommonListView" }), children: /* @__PURE__ */ jsx(CommonListView, {}) })
106
98
  }
107
99
  ) });
108
100
  }
@@ -1,4 +1,2 @@
1
1
  /// <reference types="react" />
2
- export default function CurdEditPanel(props: {
3
- fullScreen?: boolean;
4
- }): import("react").JSX.Element | null | undefined;
2
+ export default function CurdEditPanel(props: {}): import("react").JSX.Element | null | undefined;
@@ -1,64 +1,42 @@
1
1
  "use client";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
3
  import { useMtRouter } from "mtxuilib/hooks/use-router";
4
4
  import { MtPopupPanel } from "mtxuilib/ui/ui-mt/MtPopupPanel";
5
- import { useCallback, useMemo } from "react";
5
+ import { useMemo } from "react";
6
6
  import { useGomtmSuspenseQuery } from "../../gomtmQuery";
7
7
  import { RenderViewByName } from "../DynViews";
8
+ import { useGomtmForm } from "../form-context";
8
9
  import { useListview } from "../listview/list-store";
9
10
  function CurdEditPanel(props) {
10
- const { fullScreen } = props;
11
- const setOpenEdit = useListview((x) => x.setOpenEdit);
12
- const openEdit = useListview((x) => x.openEdit);
13
- const openCreate = useListview((x) => x.openCreate);
14
- const setOpenCreate = useListview((x) => x.setOpenCreate);
15
- const viewUpdate = useListview((x) => x.viewUpdate);
16
- const viewCreate = useListview((x) => x.viewCreate);
17
- const open = openEdit || openCreate;
18
- const setOpen = useCallback((open2) => {
19
- if (openCreate) {
20
- setOpenCreate(false);
21
- }
22
- if (openEdit) {
23
- setOpenEdit(false);
24
- }
25
- }, [openCreate, openEdit, setOpenCreate, setOpenEdit]);
11
+ const open = useGomtmForm((x) => x.open);
12
+ const setOpen = useGomtmForm((x) => x.setOpen);
13
+ const fullScreen = useGomtmForm((x) => x.fullScreen);
14
+ const viewName = useGomtmForm((x) => x.viewName);
15
+ const title = useGomtmForm((x) => x.title);
26
16
  const router = useMtRouter();
27
- const viewName = useMemo(() => {
28
- if (openCreate) {
29
- return viewCreate;
30
- }
31
- if (openEdit) {
32
- return viewUpdate;
33
- }
34
- }, [openCreate, openEdit, viewCreate, viewUpdate]);
35
17
  if (!open) {
36
18
  return null;
37
19
  }
38
- if (!viewUpdate) {
20
+ if (!viewName) {
39
21
  return /* @__PURE__ */ jsx("div", { children: "missing viewUpdate value" });
40
22
  }
41
- if (viewUpdate.startsWith("/")) {
42
- router.push(viewUpdate);
23
+ if (viewName.startsWith("/")) {
24
+ router.push(viewName);
43
25
  return;
44
26
  }
45
27
  if (!viewName) {
46
28
  return /* @__PURE__ */ jsx("div", { children: "missing viewName" });
47
29
  }
48
- return /* @__PURE__ */ jsxs(Fragment, { children: [
49
- "openCrate: ",
50
- JSON.stringify(openCreate, null, 2),
51
- /* @__PURE__ */ jsx(
52
- MtPopupPanel,
53
- {
54
- open,
55
- onOpenChange: setOpen,
56
- fullScreen,
57
- title: "create",
58
- children: /* @__PURE__ */ jsx(RenderViewByName, { name: viewName })
59
- }
60
- )
61
- ] });
30
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
31
+ MtPopupPanel,
32
+ {
33
+ open,
34
+ onOpenChange: setOpen,
35
+ fullScreen,
36
+ title,
37
+ children: /* @__PURE__ */ jsx(RenderViewByName, { name: viewName })
38
+ }
39
+ ) });
62
40
  }
63
41
  const WithLoadGetData = (props) => {
64
42
  const { children } = props;
@@ -0,0 +1,17 @@
1
+ import { PropsWithChildren } from 'react';
2
+ interface GomtmFormProps {
3
+ open?: boolean;
4
+ fullScreen?: boolean;
5
+ viewName: string;
6
+ title?: string;
7
+ }
8
+ export interface GomtmFormState extends GomtmFormProps {
9
+ setOpen: (open: boolean) => void;
10
+ setFullScreen: (open: boolean) => void;
11
+ setTitle: (title: string) => void;
12
+ }
13
+ export declare const gomtmFormContext: import("react").Context<import("zustand").StoreApi<GomtmFormState> | null>;
14
+ export declare const GomtmFormProvider: (props: PropsWithChildren<GomtmFormProps>) => import("react").JSX.Element;
15
+ export declare function useGomtmForm<T>(selector: (state: GomtmFormState) => T): T;
16
+ export declare function GomtmFormDebug(): import("react").JSX.Element;
17
+ export {};
@@ -0,0 +1,89 @@
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, jsxs } from "react/jsx-runtime";
34
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
35
+ import { createContext, useContext, useMemo, useRef } from "react";
36
+ import { useStore } from "zustand";
37
+ import { createStore } from "zustand/vanilla";
38
+ const createGomtmFormStore = (initProps) => {
39
+ const DEFAULT_PROPS = {
40
+ open: false,
41
+ viewName: ""
42
+ };
43
+ return createStore()((set, get) => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_PROPS), initProps), {
44
+ setOpen: (open) => set({ open }),
45
+ setFullScreen: (fullScreen) => set({ fullScreen }),
46
+ setTitle: (title) => set({ title })
47
+ }));
48
+ };
49
+ const gomtmFormContext = createContext(null);
50
+ const GomtmFormProvider = (props) => {
51
+ const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
52
+ const storeRef = useRef();
53
+ if (!storeRef.current) {
54
+ storeRef.current = createGomtmFormStore(props);
55
+ }
56
+ useMemo(() => {
57
+ var _a2;
58
+ (_a2 = storeRef.current) == null ? void 0 : _a2.setState({ open: props.open });
59
+ }, [props.open]);
60
+ useMemo(() => {
61
+ var _a2;
62
+ (_a2 = storeRef.current) == null ? void 0 : _a2.setState({ viewName: props.viewName });
63
+ }, [props.viewName]);
64
+ return /* @__PURE__ */ jsxs(gomtmFormContext.Provider, { value: storeRef.current, children: [
65
+ children,
66
+ /* @__PURE__ */ jsx(GomtmFormDebug, {})
67
+ ] });
68
+ };
69
+ function useGomtmForm(selector) {
70
+ const store = useContext(gomtmFormContext);
71
+ if (!store)
72
+ throw new Error("useGomtmForm Missing GomtmFormProvider in the tree");
73
+ return useStore(store, selector);
74
+ }
75
+ function GomtmFormDebug() {
76
+ const open = useGomtmForm((x) => x.open);
77
+ const viewName = useGomtmForm((x) => x.viewName);
78
+ return /* @__PURE__ */ jsxs("div", { children: [
79
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => {
80
+ }, children: "forminfo" }),
81
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify({ open, viewName }, null, 2) })
82
+ ] });
83
+ }
84
+ export {
85
+ GomtmFormDebug,
86
+ GomtmFormProvider,
87
+ gomtmFormContext,
88
+ useGomtmForm
89
+ };
@@ -1,14 +1,18 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useMtRouter } from "mtxuilib/hooks/use-router";
3
4
  import { Icons } from "mtxuilib/icons/icons";
4
5
  import { cn } from "mtxuilib/lib/utils";
5
6
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "mtxuilib/ui/dropdown-menu";
6
7
  import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious } from "mtxuilib/ui/pagination";
7
8
  import { MtButton } from "mtxuilib/ui/ui-mt/Button";
8
- import { lazy, useState } from "react";
9
+ import { Suspense, lazy, useCallback, useMemo, useState } from "react";
9
10
  import { MtmErrorView } from "../../components/MtmErrorView";
10
11
  import { useGomtmSuspenseInfiniteQuery } from "../../gomtmQuery";
12
+ import CurdEditPanel from "../edit/CurdEditPanel";
13
+ import { GomtmFormProvider } from "../form-context";
11
14
  import { CommontListResView } from "../list-item/ListViewLayoutRender";
15
+ import { PanelRemove } from "../remove/RemovePanel";
12
16
  import { useListview } from "./list-store";
13
17
  const ALL_Layouts = [
14
18
  "default",
@@ -20,6 +24,31 @@ function CommonListView() {
20
24
  const svc = useListview((x) => x.svc);
21
25
  const methodList = useListview((x) => x.methodList);
22
26
  const paramList = useListview((x) => x.paramsList);
27
+ const setOpenEdit = useListview((x) => x.setOpenEdit);
28
+ const openEdit = useListview((x) => x.openEdit);
29
+ const openCreate = useListview((x) => x.openCreate);
30
+ const setOpenCreate = useListview((x) => x.setOpenCreate);
31
+ const viewUpdate = useListview((x) => x.viewUpdate);
32
+ const viewCreate = useListview((x) => x.viewCreate);
33
+ const open = openEdit || openCreate;
34
+ const setOpen = useCallback((open2) => {
35
+ if (openCreate) {
36
+ setOpenCreate(false);
37
+ }
38
+ if (openEdit) {
39
+ setOpenEdit(false);
40
+ }
41
+ }, [openCreate, openEdit, setOpenCreate, setOpenEdit]);
42
+ const router = useMtRouter();
43
+ const viewName = useMemo(() => {
44
+ if (openCreate) {
45
+ return viewCreate;
46
+ }
47
+ if (openEdit) {
48
+ return viewUpdate;
49
+ }
50
+ return "";
51
+ }, [openCreate, openEdit, viewCreate, viewUpdate]);
23
52
  const listQuery = useGomtmSuspenseInfiniteQuery(svc, methodList, paramList);
24
53
  if (!(listQuery == null ? void 0 : listQuery.data)) {
25
54
  return null;
@@ -50,7 +79,27 @@ function CommonListView() {
50
79
  /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationEllipsis, {}) }),
51
80
  /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
52
81
  ] }) }),
53
- /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1", children: /* @__PURE__ */ jsx(ListViewActions, {}) })
82
+ /* @__PURE__ */ jsx("div", { className: "absolute right-1 top-1", children: /* @__PURE__ */ jsx(ListViewActions, {}) }),
83
+ /* @__PURE__ */ jsxs(Suspense, { children: [
84
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify({
85
+ open,
86
+ viewName,
87
+ viewUpdate,
88
+ viewCreate
89
+ }, null, 2) }),
90
+ /* @__PURE__ */ jsxs(
91
+ GomtmFormProvider,
92
+ {
93
+ open,
94
+ fullScreen: true,
95
+ viewName,
96
+ children: [
97
+ /* @__PURE__ */ jsx(CurdEditPanel, {}),
98
+ /* @__PURE__ */ jsx(PanelRemove, {})
99
+ ]
100
+ }
101
+ )
102
+ ] })
54
103
  ] });
55
104
  }
56
105
  const ListViewActions = () => {
@@ -17,8 +17,8 @@ interface ListViewStateProps {
17
17
  layout?: string;
18
18
  data?: any;
19
19
  error?: any;
20
- viewUpdate?: string;
21
- viewCreate?: string;
20
+ viewUpdate: string;
21
+ viewCreate: string;
22
22
  curdView?: PlainMessage<CurdView>;
23
23
  }
24
24
  export interface ListViewState extends ListViewStateProps {
@@ -34,8 +34,7 @@ export interface ListViewState extends ListViewStateProps {
34
34
  setDetailData: (detailData: any) => void;
35
35
  }
36
36
  export declare const listViewContext: import("react").Context<import("zustand").StoreApi<ListViewState> | null>;
37
- type BearProviderProps = React.PropsWithChildren<ListViewStateProps>;
38
- export declare const ListViewStoreProvider: (props: BearProviderProps) => import("react").JSX.Element;
37
+ export declare const ListViewStoreProvider: (props: PropsWithChildren<ListViewStateProps>) => import("react").JSX.Element;
39
38
  export declare const ListView: (props: Omit<ComponentProps<typeof ListViewStoreProvider>, 'backendUrl'> & PropsWithChildren) => import("react").JSX.Element;
40
39
  export declare function useListview<T>(selector: (state: ListViewState) => T): T;
41
40
  export declare const useCurdUpdateMutation: () => import("@tanstack/react-query").UseMutationResult<unknown, any, any, any>;
@@ -46,7 +46,9 @@ const createListviewStore = (initProps) => {
46
46
  methodGet: "",
47
47
  methodDelete: "",
48
48
  methodCreate: "",
49
- backendUrl: ""
49
+ backendUrl: "",
50
+ viewUpdate: "",
51
+ viewCreate: ""
50
52
  };
51
53
  return createStore()((set, get) => __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_PROPS), initProps), {
52
54
  openRemove: false,
@@ -60,27 +62,9 @@ const createListviewStore = (initProps) => {
60
62
  setCookie(CONST_cookieListViewLayout, layout);
61
63
  return set((state) => ({ layout }));
62
64
  },
63
- // loadListData: async () => {
64
- // const baseUrl = get().backendUrl || ""
65
- // const apiUrl = (new URL(MTM_API_PREFIX, baseUrl)).toString()
66
- // console.log("loadListData, apiUrl:", apiUrl)
67
- // const data = await goMtmQueryFn({
68
- // svc: get().svc,
69
- // method: get().methodList,
70
- // input: get().paramsList,
71
- // options: {
72
- // url: apiUrl
73
- // }
74
- // })
75
- // set({ data })
76
- // return data
77
- // },
78
65
  nextPage: () => {
79
66
  },
80
- // setEditRender: (editRender) => set({ editRender }),
81
- // setCreateRender: (createRender) => set({ createRender }),
82
67
  setDetailData: (detailData) => set({ detailData })
83
- // setEeditorComponentName: (editorComponentName) => set({ editorComponentName }),
84
68
  }));
85
69
  };
86
70
  const listViewContext = createContext(null);