gomtm 0.0.352 → 0.0.354

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.
@@ -5,8 +5,8 @@ import { MtPopupPanel } from "mtxuilib/ui/ui-mt/MtPopupPanel";
5
5
  import { useMemo } from "react";
6
6
  import { useGomtmSuspenseQuery } from "../../gomtmQuery";
7
7
  import { RenderViewByName } from "../DynViews";
8
- import { useGomtmForm } from "../form-context";
9
8
  import { useListview } from "../listview/list-store";
9
+ import { useGomtmForm } from "./form-context";
10
10
  function CurdEditPanel(props) {
11
11
  const open = useGomtmForm((x) => x.open);
12
12
  const setOpen = useGomtmForm((x) => x.setOpen);
@@ -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 | null;
17
+ export {};
@@ -0,0 +1,92 @@
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 { createContext, useContext, useMemo, useRef } from "react";
35
+ import { useStore } from "zustand";
36
+ import { createStore } from "zustand/vanilla";
37
+ import { useGomtm } from "../../store/mtapp-store";
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
+ const debug = useGomtm((x) => x.debug);
79
+ if (!debug) {
80
+ return null;
81
+ }
82
+ return /* @__PURE__ */ jsxs("div", { className: "bg-blue-100 p-2", children: [
83
+ /* @__PURE__ */ jsx("h1", { children: "GomtmFormDebug" }),
84
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify({ open, viewName }, null, 2) })
85
+ ] });
86
+ }
87
+ export {
88
+ GomtmFormDebug,
89
+ GomtmFormProvider,
90
+ gomtmFormContext,
91
+ useGomtmForm
92
+ };
@@ -10,7 +10,7 @@ import { Suspense, lazy, useCallback, useMemo, useState } from "react";
10
10
  import { MtmErrorView } from "../../components/MtmErrorView";
11
11
  import { useGomtmSuspenseInfiniteQuery } from "../../gomtmQuery";
12
12
  import CurdEditPanel from "../edit/CurdEditPanel";
13
- import { GomtmFormProvider } from "../form-context";
13
+ import { GomtmFormProvider } from "../edit/form-context";
14
14
  import { CommontListResView } from "../list-item/ListViewLayoutRender";
15
15
  import { PanelRemove } from "../remove/RemovePanel";
16
16
  import { useListview } from "./list-store";
@@ -80,26 +80,18 @@ function CommonListView() {
80
80
  /* @__PURE__ */ jsx(PaginationItem, { children: /* @__PURE__ */ jsx(PaginationNext, { href: "#" }) })
81
81
  ] }) }),
82
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({
83
+ /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsxs(
84
+ GomtmFormProvider,
85
+ {
85
86
  open,
87
+ fullScreen: true,
86
88
  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
- ] })
89
+ children: [
90
+ /* @__PURE__ */ jsx(CurdEditPanel, {}),
91
+ /* @__PURE__ */ jsx(PanelRemove, {})
92
+ ]
93
+ }
94
+ ) })
103
95
  ] });
104
96
  }
105
97
  const ListViewActions = () => {
@@ -112,7 +104,6 @@ const ListViewActions = () => {
112
104
  /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "List \u64CD\u4F5C" }),
113
105
  /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
114
106
  /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsx(DropdownMenuItem, { onClick: () => {
115
- console.log("setOpenCreate");
116
107
  setOpenCreate(true);
117
108
  setOpen(false);
118
109
  }, children: "create" }) }),