gomtm 0.0.387 → 0.0.388

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