gomtm 0.0.383 → 0.0.385

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,2 +1,15 @@
1
- /// <reference types="react" />
2
- export declare const ChildrenDebug: (props: any) => import("react").JSX.Element;
1
+ import { PropsWithChildren } from "react";
2
+ export interface DemoChildrenProps {
3
+ originPropsList?: any;
4
+ designMode?: boolean;
5
+ overrideData?: any;
6
+ }
7
+ export interface DemoChildrenState extends DemoChildrenProps {
8
+ setOriginPropsList: (debugData: any) => void;
9
+ setDesignMode: (designMode: boolean) => void;
10
+ setOverrideData: (overrideData: any) => void;
11
+ }
12
+ export declare const blockContext: import("react").Context<import("zustand").StoreApi<DemoChildrenState> | null>;
13
+ export declare const DemoChildrenProvider: (props: PropsWithChildren<DemoChildrenProps>) => import("react").JSX.Element;
14
+ export declare function useDemoChildrenBlock<T>(selector: (state: DemoChildrenState) => T): T;
15
+ export declare const BlockCanva: (props: any) => import("react").JSX.Element;
@@ -18,29 +18,160 @@ var __spreadValues = (a, b) => {
18
18
  return a;
19
19
  };
20
20
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import { Fragment, jsx } from "react/jsx-runtime";
22
- import { Children, createElement } from "react";
23
- import { useForm } from "react-hook-form";
24
- const ChildrenDebug = (props) => {
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 { Fragment, jsx, jsxs } from "react/jsx-runtime";
34
+ import { cn } from "mtxuilib/lib/utils";
35
+ import { Dialog, DialogContent, DialogTrigger } from "mtxuilib/ui/dialog";
36
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
37
+ import { Children, createContext, createElement, useContext, useMemo, useRef, useState } from "react";
38
+ import { createStore, useStore } from "zustand";
39
+ import { MtBlockRender, getComponentName } from "./blockRegister";
40
+ const createDemoChildrenStore = (initProps) => {
41
+ return createStore()((set, get) => __spreadProps(__spreadValues({}, initProps), {
42
+ setOriginPropsList: (debugData) => set({ originPropsList: debugData }),
43
+ setDesignMode: (designMode) => set({ designMode }),
44
+ setOverrideData: (overrideData) => set({ overrideData })
45
+ }));
46
+ };
47
+ const blockContext = createContext(null);
48
+ const DemoChildrenProvider = (props) => {
49
+ const _a = props, { children } = _a, etc = __objRest(_a, ["children"]);
50
+ const storeRef = useRef();
51
+ if (!storeRef.current) {
52
+ storeRef.current = createDemoChildrenStore(props);
53
+ }
54
+ return /* @__PURE__ */ jsxs(blockContext.Provider, { value: storeRef.current, children: [
55
+ /* @__PURE__ */ jsx(BlockDesignToolbar, {}),
56
+ children
57
+ ] });
58
+ };
59
+ function useDemoChildrenBlock(selector) {
60
+ const store = useContext(blockContext);
61
+ if (!store)
62
+ throw new Error("useDemoChildrenBlock Missing DemoChildrenProvider in the tree");
63
+ return useStore(store, selector);
64
+ }
65
+ const BlockCanva = (props) => {
25
66
  const { children } = props;
26
- const methods = useForm({});
27
67
  if (!children) {
28
68
  return /* @__PURE__ */ jsx("div", { children: "no children" });
29
69
  }
30
- return /* @__PURE__ */ jsx(Fragment, { children: Children.map(children, (child) => {
31
- var _a;
32
- console.log({
33
- "\u5B50\u7EC4\u4EF6\u540D\u79F0": child.props.name,
34
- "\u5B50\u7EC4\u4EF6\u7C7B\u578B": children.type,
35
- "\u5176\u4ED6\u5C5E\u6027": children.props,
36
- "\u7EC4\u4EF6\u540D\u79F0": (_a = children.type) == null ? void 0 : _a.name
37
- });
38
- return child.props.name ? createElement(child.type, __spreadValues({}, __spreadProps(__spreadValues({}, child.props), {
39
- register: methods.register,
40
- key: child.props.name
41
- }))) : child;
70
+ return /* @__PURE__ */ jsx(DemoChildrenProvider, { children: /* @__PURE__ */ jsx(ChildrenDebugInner, { children }) });
71
+ };
72
+ const ChildrenDebugInner = (props) => {
73
+ const { children } = props;
74
+ const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
75
+ const setDebugData = useDemoChildrenBlock((x) => x.setOriginPropsList);
76
+ const designMode = useDemoChildrenBlock((x) => x.designMode);
77
+ useMemo(() => {
78
+ let data2 = [];
79
+ {
80
+ Children.map(children, (child) => {
81
+ const compName = getComponentName(child.type);
82
+ const debugData = {
83
+ "blockType": compName,
84
+ "props": child.props
85
+ };
86
+ data2 = [...data2, debugData];
87
+ });
88
+ }
89
+ setDebugData(data2);
90
+ }, [children, setDebugData]);
91
+ if (!children) {
92
+ return /* @__PURE__ */ jsx("div", { children: "no children" });
93
+ }
94
+ return /* @__PURE__ */ jsx("div", { className: cn(
95
+ designMode && "bg-red-300 shadow-md outline"
96
+ ), children: Children.map(children, (child, i) => {
97
+ return designMode ? /* @__PURE__ */ jsx(ChildrenEditMode, { child, i }) : /* @__PURE__ */ jsx(ChildrenOrigin, { child, i });
42
98
  }) });
43
99
  };
100
+ function ChildrenOrigin(props) {
101
+ const { child, i } = props;
102
+ const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
103
+ const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
104
+ return /* @__PURE__ */ jsx(Fragment, { children: createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)) });
105
+ }
106
+ function ChildrenEditMode(props) {
107
+ var _a;
108
+ const { child, i } = props;
109
+ const [open, setOpen] = useState(false);
110
+ const originPropsList = useDemoChildrenBlock((x) => x.originPropsList);
111
+ const setOriginPropsList = useDemoChildrenBlock((x) => x.setOriginPropsList);
112
+ const oriProps = useMemo(() => {
113
+ return originPropsList[i];
114
+ }, [i, originPropsList]);
115
+ const Editor = (_a = child.type) == null ? void 0 : _a.Editor;
116
+ const overProps = useMemo(() => originPropsList && originPropsList[i].props, [i, originPropsList]);
117
+ return /* @__PURE__ */ jsxs("div", { className: " relative", children: [
118
+ /* @__PURE__ */ jsxs(
119
+ MtButton,
120
+ {
121
+ className: " absolute right-0 top-0",
122
+ onClick: () => {
123
+ setOpen(true);
124
+ },
125
+ children: [
126
+ "ed(",
127
+ i,
128
+ ")"
129
+ ]
130
+ }
131
+ ),
132
+ createElement(child.type, __spreadValues(__spreadValues({}, child.props), overProps)),
133
+ /* @__PURE__ */ jsx(Dialog, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
134
+ "editor",
135
+ Editor && /* @__PURE__ */ jsx(Editor, { preProps: oriProps, setNewProps: (values) => {
136
+ console.log("\u8BBE\u7F6E\u65B0\u503C", values);
137
+ setOriginPropsList(originPropsList.map((item, j) => {
138
+ if (i == j) {
139
+ return { props: values };
140
+ }
141
+ return item;
142
+ }));
143
+ } })
144
+ ] }) })
145
+ ] });
146
+ }
147
+ const BlockDesignToolbar = () => {
148
+ const debugData = useDemoChildrenBlock((x) => x.originPropsList);
149
+ const designMode = useDemoChildrenBlock((x) => x.designMode);
150
+ const setDesignMode = useDemoChildrenBlock((x) => x.setDesignMode);
151
+ return /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-1 bg-slate-600 p-2", children: [
152
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => {
153
+ setDesignMode(!designMode);
154
+ }, children: "edit" }),
155
+ /* @__PURE__ */ jsxs(Dialog, { children: [
156
+ /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "info" }) }),
157
+ /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx("pre", { children: JSON.stringify(debugData, null, 2) }) })
158
+ ] }),
159
+ /* @__PURE__ */ jsxs(Dialog, { children: [
160
+ /* @__PURE__ */ jsx(DialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(MtButton, { children: "reRender" }) }),
161
+ /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsx(RenderByPresistData, { data: debugData }) })
162
+ ] })
163
+ ] });
164
+ };
165
+ function RenderByPresistData(props) {
166
+ const { data } = props;
167
+ const items = data;
168
+ return /* @__PURE__ */ jsx("div", { className: "bg-yellow-100 p-2", children: items.map((item, i) => {
169
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(MtBlockRender, { type: item.blockType, compProps: item.props }) }, i);
170
+ }) });
171
+ }
44
172
  export {
45
- ChildrenDebug
173
+ BlockCanva,
174
+ DemoChildrenProvider,
175
+ blockContext,
176
+ useDemoChildrenBlock
46
177
  };
@@ -1,10 +1,9 @@
1
1
  import { Fragment, jsx } from "react/jsx-runtime";
2
2
  import { Suspense } from "react";
3
3
  import { BlockProvider } from "./block-store";
4
- import { MtBlockRender } from "./blockRegister";
5
4
  function MtBlock(props) {
6
5
  const { id, type, blockProps } = props;
7
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading block" }), children: /* @__PURE__ */ jsx(BlockProvider, { id, type, children: /* @__PURE__ */ jsx(MtBlockRender, {}) }) }) });
6
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { children: "loading block" }), children: /* @__PURE__ */ jsx(BlockProvider, { id, type }) }) });
8
7
  }
9
8
  export {
10
9
  MtBlock
@@ -1,3 +1,8 @@
1
1
  import { ComponentType } from "react";
2
- export declare const registerBlock: (type: string, comp: ComponentType<any>) => void;
3
- export declare function MtBlockRender(): import("react").JSX.Element;
2
+ export declare const getComponentName: (comp: any) => any;
3
+ export declare const registerBlock: (comp: ComponentType<any>, type?: string) => void;
4
+ export declare const registAllBlock: () => void;
5
+ export declare function MtBlockRender(props: {
6
+ type: string;
7
+ compProps: any;
8
+ }): import("react").JSX.Element;
@@ -16,20 +16,28 @@ var __spreadValues = (a, b) => {
16
16
  return a;
17
17
  };
18
18
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
19
- import { lazy } from "react";
20
- import { useBlock } from "./block-store";
19
+ import HelloBlock from "./blocks/hello";
20
+ import Hello2Block from "./blocks/hello2";
21
+ const getComponentName = (comp) => {
22
+ let name1 = comp.blockName;
23
+ if (!name1) {
24
+ name1 = comp == null ? void 0 : comp.name;
25
+ }
26
+ return name1;
27
+ };
21
28
  const blocks = {};
22
- const registerBlock = (type, comp) => {
23
- blocks[type] = comp;
29
+ const registerBlock = (comp, type) => {
30
+ const name = getComponentName(comp);
31
+ console.log("registerBlock", name);
32
+ blocks[name] = comp;
33
+ };
34
+ const registAllBlock = () => {
35
+ registerBlock(HelloBlock);
36
+ registerBlock(Hello2Block);
24
37
  };
25
- const LzHelloBlock = lazy(() => import("./blocks/HelloText"));
26
- const LzHello2Block = lazy(() => import("./blocks/Hello2Block"));
27
- registerBlock("hello", LzHelloBlock);
28
- registerBlock("hello2", LzHello2Block);
29
- function MtBlockRender() {
30
- const id = useBlock((x) => x.id);
31
- const type = useBlock((x) => x.type);
32
- const blockProps = useBlock((x) => x.props);
38
+ registAllBlock();
39
+ function MtBlockRender(props) {
40
+ const { compProps, type } = props;
33
41
  const BlockComp = blocks[type];
34
42
  if (!BlockComp) {
35
43
  return /* @__PURE__ */ jsxs("div", { className: "bg-600 mx-auto p-8", children: [
@@ -37,9 +45,11 @@ function MtBlockRender() {
37
45
  type
38
46
  ] });
39
47
  }
40
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(BlockComp, __spreadValues({}, blockProps)) });
48
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(BlockComp, __spreadValues({}, compProps)) });
41
49
  }
42
50
  export {
43
51
  MtBlockRender,
52
+ getComponentName,
53
+ registAllBlock,
44
54
  registerBlock
45
55
  };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export default function HelloBlock(props: {
3
+ id: string;
4
+ text?: string;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { jsxs } from "react/jsx-runtime";
3
+ function HelloBlock(props) {
4
+ const { id, text } = props;
5
+ return /* @__PURE__ */ jsxs("div", { className: "bg-slate-100 p-2", children: [
6
+ "hello block: ",
7
+ id,
8
+ ",text:",
9
+ text
10
+ ] });
11
+ }
12
+ export {
13
+ HelloBlock as default
14
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export default function HelloBlock(props: {
3
+ text?: string;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ function HelloBlock(props) {
3
+ const { text } = props;
4
+ return /* @__PURE__ */ jsxs("div", { className: "border bg-slate-100 p-2 shadow-md outline", children: [
5
+ /* @__PURE__ */ jsx("h1", { children: "hello-block" }),
6
+ /* @__PURE__ */ jsx("div", { className: "bg-slate-300 p-2", children: text })
7
+ ] });
8
+ }
9
+ export {
10
+ HelloBlock as default
11
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ export default function HelloBlockEditor(props: {
3
+ preProps: any;
4
+ setNewProps: (props: any) => void;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { MtButton } from "mtxuilib/ui/ui-mt/Button";
3
+ function HelloBlockEditor(props) {
4
+ const { preProps, setNewProps } = props;
5
+ return /* @__PURE__ */ jsxs("div", { children: [
6
+ /* @__PURE__ */ jsx("h1", { children: "hello editor" }),
7
+ /* @__PURE__ */ jsx(MtButton, { onClick: () => {
8
+ console.log("todo set text");
9
+ setNewProps({ text: "new text-------------------" });
10
+ }, children: "set text" }),
11
+ /* @__PURE__ */ jsx("pre", { children: JSON.stringify(preProps, null, 2) })
12
+ ] });
13
+ }
14
+ export {
15
+ HelloBlockEditor as default
16
+ };
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ declare function HelloBlock(props: {
3
+ id: string;
4
+ text?: string;
5
+ }): import("react").JSX.Element;
6
+ declare namespace HelloBlock {
7
+ var blockName: string;
8
+ var Editor: import("react").LazyExoticComponent<typeof import("./edit").default>;
9
+ }
10
+ export default HelloBlock;
@@ -0,0 +1,29 @@
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 } from "react/jsx-runtime";
19
+ import { lazy } from "react";
20
+ const LzHelloBlock = lazy(() => import("./Hello"));
21
+ const LzEdit = lazy(() => import("./edit"));
22
+ function HelloBlock(props) {
23
+ return /* @__PURE__ */ jsx(LzHelloBlock, __spreadValues({}, props));
24
+ }
25
+ HelloBlock.blockName = "hello-block";
26
+ HelloBlock.Editor = LzEdit;
27
+ export {
28
+ HelloBlock as default
29
+ };
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export default function Hello2Block(props: {
3
+ id: string;
4
+ }): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsxs } from "react/jsx-runtime";
3
+ function Hello2Block(props) {
4
+ const { id } = props;
5
+ return /* @__PURE__ */ jsxs("div", { className: "mx-auto flex gap-2 bg-blue-100 p-2", children: [
6
+ "hello2 block: ",
7
+ id
8
+ ] });
9
+ }
10
+ export {
11
+ Hello2Block as default
12
+ };